I have python code
Код: Выделить всё
from Crypto.Cipher import AES def pad(data): block_size = 16 bytes_to_add = block_size - ((len(data) % block_size) or block_size) return data + (b'\0' * bytes_to_add) cipher = AES.new(b"4452038393672345", AES.MODE_ECB) body = pad("asa masa".encode('utf-8')) content = base64.b64encode(cipher.encrypt(body)).decode('ascii')
I want to port python code to php using openssl
Код: Выделить всё
function pad($data) { $block_size = 16; $bytes_to_add = $block_size - ((strlen($data) % $block_size) ?: $block_size); return $data . str_repeat("\0", $bytes_to_add); } $cipher = "AES-128-ECB"; $options = OPENSSL_RAW_DATA; $plainText = pad("asa masa"); $key = '4452038393672345'; $encryptedText = openssl_encrypt($plainText, $cipher, $key, $options); $encodedText = base64_encode($encryptedText);
Another code in php
Код: Выделить всё
$rawData = openssl_encrypt(pad("asa masa"), 'AES-128-ECB', '4452038393672345');
If anyone is interested, do it this way and everything is fine
Код: Выделить всё
If anyone is interested, do it this way and everything is fine $encrypted = openssl_encrypt(pad("asa masa"), 'AES-128-ECB', '4452038393672345',OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY | OPENSSL_ZERO_PADDING); $encrypted=base64_encode($encrypted);
Thanks
Источник: https://stackoverflow.com/questions/781 ... hp-openssl