|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-11-17 03:14 UTC] stjeffy at hotmail dot com
Description: ------------ I work with mcrypt to encrypt the string by Triple DES. But I meet with the key length problem. I use a 24BYTE key, the key is(HEX)3FD3A3DABD10B0FF6EAFB5A0103D386EAF6E3F8CAED6CD93 After executing a instance, the system reports the following error: mcrypt_generic_init(): Key size too large; supplied length: 48, max: 24 in and cut off the half of the original key to calculate the 3des result. And I find there exists the same problem in php.net' online help-- the 2nd example provided in http://www.php.net/manual/en/ref.mcrypt.php. Reproduce code: --------------- $strSource = "http://www.php.net/test.php"; $strKey = "3FD3A3DABD10B0FF6EAFB5A0103D386EAF6E3F8CAED6CD93"; $td = mcrypt_module_open (MCRYPT_3DES, '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); mcrypt_generic_init ($td, $strKey, $iv); $strCode = mcrypt_generic ($td, $strSource); mcrypt_generic_end ($td); echo base64_encode($strCode); Expected result: ---------------- w6e8c9Tp0/PejfYYvgJJu3cHUXYg29CQAthGmi480Ng= Actual result: -------------- LMke4PuG37H9vP5gvRoVwQkX0hZrtfE9NB/az+lSLcc= PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 08:00:01 2025 UTC |
The key is expected to be in binary, not hex. Try using pack() to convert the string from hex to bin, i.e. $strKey = pack('H48', "3FD3..."); J