php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26283 3des keys length
Submitted: 2003-11-17 03:14 UTC Modified: 2003-11-17 23:00 UTC
From: stjeffy at hotmail dot com Assigned:
Status: Not a bug Package: mcrypt related
PHP Version: 4.3.2 OS: windows 2000,linux
Private report: No CVE-ID: None
 [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=

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-17 14:00 UTC] jay@php.net
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 
 [2003-11-17 23:00 UTC] stjeffy at hotmail dot com
Thank you for your reply.
I had try to convert the hex string to the binary string, however The actual result was not the expected result.
The expected result is calculated by C Language.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC