Mcrypt 3DES encrypt/decrypt Help
| From: | yangguang1981 at gmail dot com | Date: | Mon, 07 Nov 2005 04:56:08 +0000 |
| Subject: | Mcrypt 3DES encrypt/decrypt Help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-225221@lists.php.net to get a copy of this message | ||
Hi all:
I wan't to use php_mcrpyt to encrypt data,but have a problem in it !
Hint:
Warning: mcrypt_encrypt(): Size of key is too large for this algorithm
Algorithm : 3DES
Key: 48bit
<?php
// Designate string to be encrypted
$string =3D "Applied Cryptography, by Bruce Schneier, is a wonderful
cryptography reference.";
// Encryption/decryption key
$key =3D "C770634F437346D7FC8FA22F9287849E741A33438EEDEAAD";
// Encryption Algorithm
$cipher_alg =3D MCRYPT_3DES;
// Create the initialization vector for added security.
$iv =3D mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,
MCRYPT_MODE_ECB), MCRYPT_RAND);
// Output original string
print "Original string: $string ";
// Encrypt $string
$encrypted_string =3D mcrypt_encrypt($cipher_alg, $key, $string,
MCRYPT_MODE_CBC, $iv);
// Convert to hexadecimal and output to browser
print "Encrypted string: ".bin2hex($encrypted_string)." ";
$decrypted_string =3D mcrypt_decrypt($cipher_alg, $key,
$encrypted_string, MCRYPT_MODE_CBC, $iv);
print "Decrypted string: $decrypted_string";
?>