|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: stjeffy at hotmail dot com
New email:
PHP Version: OS:


 [2003-11-17 03:14 UTC] stjeffy at hotmail dot com
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' online help-- the 2nd example provided in

Reproduce code:
$strSource = "";
$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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-17 14:00 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..."); 
 [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: Mon Mar 04 10:01:27 2024 UTC