I've never used the mcrypt functions, but from a quick read of the
documentation I think you are using a 384 bit key!... Each letter in your
key string is a 8bit ASCII character, and since you have 48 chars, you have
8*48 bits.
The documentation says:
" Key is the key with which the data will be encrypted. If it's smaller that
the required keysize, it is padded with '\0'. It is better not to use ASCII
strings for keys. It is recommended to use the mhash functions to create a
key from a string. "
and gives the example:
$key = "This is a very secret key";
In that example the key is 25 bytes long, therefore 200 bits long, and then
padded with \0s.
If you want your key to represent the hex of the key then I believe you must
use pack(), or one of the user comments on the bin2hex() help page (namely
the hexbin() function).
Hope this helps
Andrew
----- Original Message -----
From: <yangguang1981@xxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Monday, November 07, 2005 4:56 AM
Subject: Mcrypt 3DES encrypt/decrypt Help
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";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php