Re: Mcrypt Function - New to it
| From: | Tom Rogers | Date: | Fri, 31 May 2002 03:54:42 +0000 |
| Subject: | Re: Mcrypt Function - New to it | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-100047@lists.php.net to get a copy of this message | ||
Hi
Here are a couple of functions that should help to get you started, iv is set to all 0's so it does not have to be passed around or stored in sessions. It is base64 encoded so it can be stored or passed to the browser.
Function Code_id($id,$password){
$eid = 0;
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $password, $iv);
$eid = base64_encode(mcrypt_generic ($td, $id));
mcrypt_generic_end ($td);
return $eid;
}
Function Get_id($eid,$password){
$id = 0;
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $password, $iv);
$id = mdecrypt_generic ($td, base64_decode($eid));
mcrypt_generic_end ($td);
return $id;
}
Tom
At 11:07 PM 30/05/2002 -0400, Tom Ray wrote:
Hi there..some what a new programmer when it comes to all this. I'm trying to encrypt some data and then decrypt it. It doesn't have to be high bit encryption just something simple like 3DES. But I keep getting it wrong. Any help would be greatful. Here's the piece of code: $iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_3DES, MCRYPT_MODE_ECB), MCRYPT_RAND); $key = md5("Secret Key"); $sample2 = "Hello"; $lockdata = mcrypt_encrypt (MCRYPT_3DES, $key, $sample2, MCRYPT_MODE_ECB, $iv); echo "$lockdata\n"; $text = mcrypt_decrypt (MCRYPT_3DES, $key, $lockdata, MCRPYT_MODE_ECB, $iv); echo "$text\n"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php