|
Posted by Tom Rogers on 04/13/05 02:55
Hi,
Wednesday, April 13, 2005, 5:14:25 AM, you wrote:
MH> Do you do this on the encryption or the decryption section or both?
I do it on both, here is a class I use that may help:
class encryptClass{
var $secret;
function encryptClass(){
$this->secret = 'put secret here';
}
Function encode($id){
$eid = $iv = 0;
$len = strlen($id);
$id = $len.'-'.$id;
$td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$key = substr($this->secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);
$eid = base64_encode(mcrypt_generic ($td, $id));
mcrypt_generic_deinit($td);
return $eid;
}
Function decode($eid){
$id = $iv = 0;
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$key = substr($this->secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);
$id = mdecrypt_generic ($td, base64_decode($eid));
$len = strtok($id,'-');
$id = substr($id,(strlen($len)+1),$len);
mcrypt_generic_deinit($td);
return $id;
}
}
( I encode the length of the original string so I can trim the extra
rubbish that deinit leaves behind as packing)
--
regards,
Tom
Navigation:
[Reply to this message]
|