小编Tuk*_*oid的帖子

ValueError:AES密钥必须为16、24或32个字节长PyCrypto 2.7a1

我正在为我的学校项目编程,上面有一个问题。这是我的代码:

def aes():
    #aes
    os.system('cls')
    print('1. Encrypt')
    print('2. Decrypt')

    c = input('Your choice:')

    if int(c) == 1:
        #cipher
        os.system('cls')
        print("Let's encrypt, alright")
        print('Input a text to be encrypted')
        text = input()

        f = open('plaintext.txt', 'w')
        f.write(text)
        f.close()

        BLOCK_SIZE = 32
        PADDING = '{'
        pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
        EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
        secret = os.urandom(BLOCK_SIZE)

        f = open('aeskey.txt', 'w')
        f.write(str(secret))
        f.close()

        f = open('plaintext.txt', 'r')
        privateInfo = f.read()
        f.close()

        cipher …
Run Code Online (Sandbox Code Playgroud)

python cryptography pycrypto python-3.x

-1
推荐指数
1
解决办法
6813
查看次数

标签 统计

cryptography ×1

pycrypto ×1

python ×1

python-3.x ×1