|
Posted by yangguang1981 on 11/07/05 06:56
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";
?>
[Back to original message]
|