Python AES
key는 16바이트 단위로 해야하며,
평문도 16바이트 크기로 '{'로 패딩된다.
from Crypto.Cipher import AES key="a"*16 #key = b'\xbf\xc0\x85)\x10nc\x94\x02)j\xdf\xcb\xc4\x94\x9d(\x9e[EX\xc8\xd5\xbfI{\xa2$\x05(\xd5\x32' message="keyiskey"*3 print (len(key)) #key = b'\xbf\xc0\x85)\x10nc\x94\x02)j\xdf\xcb\xc4\x94\x9d(\x9e[EX\xc8\xd5\xbfI{\xa2$\x05(\xd5\x18' #message = "this is my super secret message" cipher =AES.new(key) def pad(s): return s + ((16-len(s) %16)*'{') def encrypt(plaintext): global cipher, key print (pad(plaintext)) return cipher.encrypt(pad(plaintext)) def decrypt(ciphertext): global cipher dec = cipher.decrypt(ciphertext).decode('utf-8') l = dec.count('{') return dec[:len(dec)-l] print ("Message:",message) encrypted = encrypt(message) decrypted = decrypt(encrypted) print("Encrypted:",encrypted) print("Decrypted:",decrypted) |