Hi, Monday, December 29, 2003, 9:30:11 AM, you wrote: MW> Hello!
MW> I'm trying to use mcrypt to encrypt some values (login and password) I have MW> to pass from one website to another. You will need to pass the $iv which kinda defeats the object of it, or use a null one. Here is a class I use for this which also corrects the string lengths as decryption will usually have a few /0 tacked on to make it a block size: class encrypt_class{ var $secret; function encrypt_class(){ $this->secret = 'choose your own pass phrase 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; } } //usage $password = 'password'; $name = 'me'; $mesage[0] = $password; $message[1] = $name; $serial = serialize($message); $enc = new encrypt_class(); $enc_message = $enc->encode($serial); //send message ....?enc_message=$enc_message //next page $enc = new encrypt_class(); $serial = $enc->decode($_GET['enc_message']); $message = unserialize($serial); print_r($message); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php