如何为python py3rijndael模块的AES生成随机密钥

2024-10-06 12:56:00 发布

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

import unittest
import base64
from py3rijndael import Rijndael

def test_rijndael():
    key = 'qBS8uRhEIBsr8jr8vuY9uUpGFefYRL2HSTtrKhaI1tk='
    print(len(key))
    
    a=input("Please Enter Plain text: ")
    plain_text=a.encode('utf-8')
    rijndael = Rijndael(base64.b64decode(key), block_size=32)
    padded_text = plain_text.ljust(32, b'\x1b')
    cipher = rijndael.encrypt(padded_text)
    cipher_text = base64.b64encode(cipher)
    pl_txt=rijndael.decrypt(cipher)
    pl_txt[:len(plain_text)]
    return cipher_text

在上面的代码中,我想为安全私钥生成一个随机密钥 更改键中的任何字符以进行ex:making key='qBS8uRhEIBsr8jr8vuY9uUpGFefYRL2HSTtrKhaI1tk+'或其他东西,使测试失败,密钥大小无效。有人能帮忙吗。 Error info


Tags: keytextimporttxtlen密钥unittestpl