Python:Pycrypto解密错误

时间:2015-10-24 22:12:56

标签: python python-3.x encryption pycrypto

所以目前我一直在为我的学校开发加密和解密程序,用于他们的数据库和存储学生登录密码。我遇到了这个错误。

TypeError: a bytes-like object is required, not 'str'

如果有人可以帮我修复此错误,我们将不胜感激。

以下代码:

from Crypto.Cipher import AES
import base64
import os

def en():
    message = input("Message to encrypt: ")
    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)))

    en_Key = b'-\xdd\xe3\x12\xa5\xc9\xfbB\xb7\xe1\xf7?l\xb0\x91"\xb8\\\xae\xa4\x8a\xbfo\x0bf\xcf\xeek\xb1k\x00d'
    print('Encryption key: ', en_Key)

    cipher = AES.new(en_Key)

    encoded = EncodeAES(cipher, message)
    print('Encrypted message: ', encoded)

def de(en_Message):

    PADDING = '{'
    DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)

    en_Key = b'-\xdd\xe3\x12\xa5\xc9\xfbB\xb7\xe1\xf7?l\xb0\x91"\xb8\\\xae\xa4\x8a\xbfo\x0bf\xcf\xeek\xb1k\x00d'

    cipher = AES.new(en_Key)

    decoded = DecodeAES(cipher, en_Message)
    print('Decoded message: ', decoded)

0 个答案:

没有答案