我正在try 使用PHP中的32字符十六进制密钥从XML生成ISO/IEC 9797-1 MAC,但我无法获得预期的结果.
我try 了使用open_ssl和phpseclib的各种方法,但都没有产生预期的输出. 为了验证我的MAC,我使用网站https://paymentcardtools.com/emv-misc/mac-calculator,在那里我在数据字段中将我的XML转换为十六进制,使用填充方法1,并输入我的32位密钥.
我需要知道如何在PHP中实现同样的结果.以前有人做过这样的事吗?
$length = strlen($message);
$padding = 8 - ($length % 8);
$message .= str_repeat(chr(0), $padding);
// Separate the first DES key and 3DES key
$des_key = substr($key, 0, 8);
$tripledes_key = substr($key, 8, 16);
// Use the first DES key for CBC-MAC
$cbc_mac = openssl_encrypt($message, 'DES-ECB', $des_key, OPENSSL_RAW_DATA);
// Use 3DES for the final block
$last_block = substr($message, -8);
$tripledes_cipher = openssl_encrypt($last_block, 'DES-EDE3-ECB', $tripledes_key, OPENSSL_RAW_DATA);
// The result is the last 8 bytes of the triple DES cipher
return substr(strtoupper(bin2hex(substr($tripledes_cipher, -8))), 0, 8);