728x90
- AES 복호화 코드
- Web site 에서도 가능 : https://www.devglan.com/online-tools/aes-encryption-decryption
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
def aes_decrypt(hex_key, hex_ciphertext, hex_iv):
# 1. 헥사 문자열을 바이트로 변환
key = bytes.fromhex(hex_key)
print(len(key))
ciphertext = bytes.fromhex(hex_ciphertext)
iv = bytes.fromhex(hex_iv)
# 2. AES 복호화 객체 생성 (CBC 모드)
cipher = AES.new(key, AES.MODE_CBC, iv)
# 3. 복호화 수행 및 패딩 제거
#decrypted = unpad(cipher.decrypt(ciphertext), AES.block_size)
decrypted = cipher.decrypt(ciphertext)
print(decrypted.hex())
return decrypted.decode('utf-8')
if __name__ == "__main__":
hex_key = ".." # 16바이트 (128bit) 키
hex_iv = ".." # 16바이트 IV
hex_ciphertext = ".." # 예시 암호문 (CBC 모드로 암호화됨)
plaintext = aes_decrypt(hex_key, hex_ciphertext, hex_iv)
print("복호화된 평문:", plaintext)728x90