I am trying to compute a PHP function to have the 3DES (Triple DES) in ECB Mode. But I am getting the wrong result.
My result : 615EDC0E8EAD5DDE
Expected result : 7B66D9A5010A8035
(the expected result is computed with HSM and confirmed with the website) http://tripledes.online-domain-tools.com/
Here is my PHP function, taking as parameters :
$data = "3200000025381234"
$key = "98137332E06BBA25AEE51CFD150EA8E3"
function tripleDES($data, $key) { $key= hex2bin($key); $data = hex2bin($data); $enc = openssl_encrypt($data, 'des-ede3', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); return strtoupper(bin2hex($enc)); } What am I doing wrong ?
K1, K2, K3 = K1, so that for PHP the key is:98137332E06BBA25AEE51CFD150EA8E398137332E06BBA25which provides the expected result. A shorter key is implicitly extended to 24 bytes by padding with0-values, which produces a different result.