使用生成的随机bi一次性输入文本

2024-04-24 22:07:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试过用python实现一个非常简单的OTP,但是由于一些我不理解的原因,我得到了一个错误,它说:“ValueError:Incorrect AES key length(4 bytes)”。 我也是python和OTP的新手!你知道吗

代码如下:

from Crypto.Cipher import AES
import base64

user_input = input("Write here:")

secret_key = '1234567890'

cipher = AES.new(secret_key, AES.MODE_ECB)
encoded = base64.b64encode(cipher.encrypt(user_input))

decoded = cipher.decrypt(base64.b64decode(encoded))
print(decoded.strip())

Tags: keyimportinputsecret错误原因aesotp