Using an online encrypt/decrypt tool, using DES-ECB, I can encrypt an 8 digit hexadecimal number using an 8 digit hexadecimal key, resulting in an 8 digit hex result. I can decrypt that 8 digit result by the same key and get the original data I encrypted.
However, I cannot reproduce this locally using PHP. The encrypted result I get online, it turns out, is the first 8 of 16 digits actually produced. No problem... But when I try to decrypt locally using PHP, I need all 16 digits in order to get the original data.
How can I decrypt with only the 8 digits and still get the original data, like the online tool does?
Online results:
Encrypting:
$data = '03 67 A6 7F C2 00 0A DB';
$key = '00 F2 83 CD BA 41 6F FF';
$result = '8b be 0f 3b ae 92 56 07';
Verify: http://des.online-domain-tools.com/link/1b40d6agZYE0TFR5sM/
Decrypting:
$data = '8b be 0f 3b ae 92 56 07';
$key = '00 F2 83 CD BA 41 6F FF';
$result = '03 67 A6 7F C2 00 0A DB';
Verify: http://des.online-domain-tools.com/link/1b40e05gD5TNgMb72h/
Local PHP test:
$enc = openssl_encrypt( hex2bin('0367A67FC2000ADB'), 'DES-ECB', hex2bin('00F283CDBA416FFF'), 1);
bin2hex($enc)
results in 8bbe0f3bae9256071da486ee680f8449
If I decrypt only the first 8 hex digits, I don't get the same results I do with the online tool:
$dec = openssl_decrypt( hex2bin('8bbe0f3bae925607'), 'DES-ECB', hex2bin('00F283CDBA416FFF'), 1);
bin2hex($dec)
results in null (or false if we do not convert to hex)
But if I enter the full 16 digit hex as the encrypted data, I get the correct result:
$dec = openssl_decrypt( hex2bin('8bbe0f3bae9256071da486ee680f8449'), 'DES-ECB', hex2bin('00F283CDBA416FFF'), 1);
bin2hex($dec)
results in 0367A67FC2000ADB
This makes sense to me... but I need to be able to get this result from only the 8 digit hex, just like the online tool does. What do I need to do to make this possible?