PHP code
// php 8.1.13
$text = '1';
$key = base64_decode('3pKtqxNOolyBoJouXWwVYw==');
$iv = base64_decode('O99EDNAif90=');
$encrypted = openssl_encrypt($text, 'des-ede3-cbc', $key, OPENSSL_RAW_DATA, $iv);
$hex = strtoupper(bin2hex($encrypted));
echo $hex;
The result is FF72E6D454B84A7C
Python3.8 pycryptodome 3.20.0
import binascii
import base64
from Crypto.Cipher import DES3
from Crypto.Util.Padding import pad
key = base64.b64decode('3pKtqxNOolyBoJouXWwVYw==')
iv = base64.b64decode('O99EDNAif90=')
cipher = DES3.new(key, DES3.MODE_CBC, iv)
data = '1'
data = data.encode('utf-8')
data = pad(data, DES3.block_size)
encrypted = cipher.encrypt(data)
print(binascii.hexlify(encrypted).decode('utf-8').upper())
The result is A311743FB5D91569
Why are these two results different, and how can I make python’s results consistent with PHP’s?
I’ve tried using pycryptodome and pyDes and can’t achieve the same result as PHP
New contributor
Swilder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.