PHP OpenSSL encrypt with DES-ECB algorithm unexpected output

  algorithm, encryption, laravel, openssl, php

I’ve tried to encrypt the value with DES-ECB via PHP 7.4 (Laravel) and OpenSSL, and I try the online tool https://emvlab.org/descalc/ to encrypt value, the result was the expected.

key: 96187BBAB2BD19ACF899B74FB4E37972

Input Data: F01DCCE40F8C365ADE0A7DC03BC11DDE

The encrypted data is 355A627E977D8ECF4953C98D801E472F on online tool.
https://emvlab.org/descalc/?key=96187BBAB2BD19ACF899B74FB4E37972&iv=0000000000000000&input=f01dcce40f8c365ade0a7dc03bc11dde&mode=ecb&action=Encrypt&output=D5131A2B35766D371420F679F15969FF

When the next code written in PHP I can’t replicate the result:

$data = "F01DCCE40F8C365ADE0A7DC03BC11DDE";
$key = "96187BBAB2BD19ACF899B74FB4E37972";
$encrypted = openssl_encrypt($data, 'DES-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
echo base64_encode($encrypted); // KV8Vie63pG2ZyjW7U5NRJUwOrbsEt+lnG1hNyS331Yk=

Is there a way to get the same string that the online tool?
Thank you!

enter image description here

Source: Ask PHP

LEAVE A COMMENT