[PYTHON] PyCryptodome AES encryption and decryption process memo

AES encrypted memo.

environment Python3.7 pycryptodome 3.9.8

Source code

# -*- coding: utf-8 -*-
from Crypto.Cipher import AES

key = b"1234567890123456" 
data = b"hogehoge" #Characters to encrypt

#Encryption process
cipher = AES.new(key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(data)

print(ciphertext)
print(tag)
print(cipher.nonce)

#Decryption process
cipher_dec = AES.new(key, AES.MODE_EAX, cipher.nonce)
dec_data = cipher_dec.decrypt_and_verify(ciphertext, tag)

print(dec_data)

result

b'7\xecO,\xa4J\\:'
b'\x8eQ\x95\x0eL\xe2\xa2\xbb\x9e\xf9!\xb7\x83\xbd\xefk'
b'\x16\xe3\xf7`\x0e\x05L/\xf7\xe0\x1a\x067\xa4V\xfa'
b'hogehoge'

reference

https://pycryptodome.readthedocs.io/en/latest/src/examples.html

Recommended Posts

PyCryptodome AES encryption and decryption process memo
pycrypto encryption and decryption
Encryption and decryption with Python
About text encryption (AES encryption)