mcrypt function help

From: Date: Sun, 01 Oct 2000 21:55:52 +0000
Subject: mcrypt function help
Groups: php.general 
Request: Send a blank email to php-general+get-18221@lists.php.net to get a copy of this message
I've created two mcrypt functions by following the examples in the manual; however, I've added bin2hex and hex2bin calls so I can store the encrypted data as text not binary. Are the functions below still secure? Also, if the Initialization Vector has to stay the same to encrypt/decrypt and I'm using a database to store the data shouldn't I manually create the IV and store it for all future calls to mcrypt? Or is there a way to use a random IV? function encrypt_to_text($key, $input, $iv){ $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_CFB, ""); mcrypt_generic_init ($td, $key, $iv); $encrypted_text = bin2hex(mcrypt_generic ($td, $input)); // change to hex here mcrypt_generic_end ($td); return $encrypted_text; } function decrypt_from_text($key, $input, $iv){ $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_CFB, ""); mcrypt_generic_init ($td, $key, $iv); $decrypted_data = mdecrypt_generic ($td, pack("H" . strlen($encrypted_data), $encrypted_data)); // change to bin here mcrypt_generic_end ($td); return $decrypted_data; } $key = "this secret very secret very secret very secret"; $input = "Let us meet at 9 o'clock at the secret place."; $iv = "qswdceih"; $enc_text = encrypt_to_text($key, $input, $iv); $dec_text = decrypt_from_text($key, $enc_text, $iv); Thanks for your help, Charles

« previous php.general (#18221) next »