小编use*_*308的帖子

Python AES 256 CBC 加密 - ValueError:AES 密钥长度不正确

我想在 Python 3.8.5 上使用 AES 256 为我的明文编写加密,但是当我执行它时,我收到错误ValueError:不正确的 AES 密钥长度(64 字节)我的代码中是否有问题?

plaintext = "ABC123"
secret_key = "6789045129812345"
secret_iv = "4567891122315731"
    
key = hashlib.sha256(str(secret_key).encode('utf-8')).hexdigest()
iv = hashlib.sha256(str(secret_iv).encode('utf-8')).hexdigest()
substring_iv = iv[:16]
cipher_config = AES.new(key.encode("utf-8"), AES.MODE_CBC, substring_iv.encode("utf-8"))
results = base64.b64encode(cipher_config)

print("results : "+results)
Run Code Online (Sandbox Code Playgroud)

python encryption aes sha256

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

aes ×1

encryption ×1

python ×1

sha256 ×1