Created
November 29, 2017 02:08
-
-
Save terapyon/ab6642bb69bc28647271944b45debc07 to your computer and use it in GitHub Desktop.
AES PHP to Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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