【问题标题】:Crypto is not support python 3.x?加密不支持 python 3.x?
【发布时间】:2019-03-11 11:54:05
【问题描述】:

当我使用 python3.x 时,运行代码:

    with open('rsa_public_key.pem') as f:
    key = f.read()
    rsakey = RSA.importKey(key)
    cipher = Cipher_pkcs1_v1_5.new(rsakey)
    cipher_text = base64.b64encode(cipher.encrypt(aes_key))
    str1 = cipher_text

会报错:

  File "de_test.py", line 81, in get_login_data_inputPostString
cipher_text = base64.b64encode(cipher.encrypt(aes_key))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Crypto/Cipher/PKCS1_v1_5.py", line 137, in encrypt
em = b('\x00\x02') + ps + bchr(0x00) + message
TypeError: can't concat str to bytes

但是当我使用 python 2.6 时,它会通过。

所以加密不支持 python 3.x?

【问题讨论】:

    标签: python-3.x pycrypto


    【解决方案1】:

    在没有看到aes_key 的情况下,您似乎正在尝试将str 对象传递给您应该将bytes 对象传递给encrypt()。

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 2013-12-03
      • 1970-01-01
      • 2020-02-14
      • 2018-03-10
      • 2012-10-11
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多