Skip to content

Instantly share code, notes, and snippets.

@terapyon
Created November 29, 2017 02:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terapyon/ab6642bb69bc28647271944b45debc07 to your computer and use it in GitHub Desktop.
Save terapyon/ab6642bb69bc28647271944b45debc07 to your computer and use it in GitHub Desktop.
AES PHP to Python
import binascii
from Crypto.Cipher import AES
data = "abcdefghijklmnopqrstuvwxyz"
key = "pqrstuvwxyz$abcdefghijAB"
iv = "DEFGHTABCIESPQXO"
encrypted = "2324ab5ec7a901247bf01b08bd1956688843dad5a8e15106ca3a5b9258918527"
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted = cipher.decrypt(binascii.unhexlify(encrypted))
print(decrypted)
# b' \xea\xbc\x13\x98!xw\x0c,\xac6\xeb\x1c\x14\\Z\x0b\x0fTY\xbe\x0b^W\xcem\xa4\x9ea\xde\x1b'
decrypted.decode('utf-8')
# UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1-2: invalid continuation byte
<?php
$str = "abcdefghijklmnopqrstuvwxyz";
$method = "aes-256-cbc";
$key = 'pqrstuvwxyz$abcdefghijAB';
$iv = 'DEFGHTABCIESPQXO';
echo bin2hex(openssl_encrypt($str, $method, $key, OPENSSL_RAW_DATA, $iv));
echo "\n";
?>
'2324ab5ec7a901247bf01b08bd1956688843dad5a8e15106ca3a5b9258918527'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment