python - 如何使用 Pycryptodome AES 加密 python 中的字符串?
问题描述
我是密码学新手,我对一些代码有疑问。
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(16)
cipher = AES.new(key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(data)
file_out = open("encrypted.bin", "wb")
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
这段代码直接实现是否安全?此代码取自https://pycryptodome.readthedocs.io/en/latest/src/examples.html#encrypt-data-with-aes
如何使用生成的密钥加密字符串?