用于加密/解密的Python脚本突然不起作用

时间:2016-04-12 04:30:01

标签: python public-key-encryption

我正在刷新公钥/私钥对加密。为了向自己说明这个概念,我写了一个原始脚本。它曾经在一周前使用我的python客户端工作:

> Python 2.7.9 (default, Apr  2 2015, 15:33:21)  [GCC 4.9.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>>

今天,我尝试运行它,并收到以下错误:

work@work-IdeaPad-U330p:~/projects/Script$ python example_encrypt_decrypt.py 
Traceback (most recent call last):
  File "example_encrypt_decrypt.py", line 9, in <module>
    encrypted_message = public_key_1.encrypt(M, 24)
  File "/usr/local/lib/python2.7/dist-packages/Crypto/PublicKey/RSA.py", line 123, in __getattr__
    raise AttributeError(attrname)
AttributeError: encrypt

我正在运行的脚本是:

from Crypto.PublicKey import RSA
import binascii

private_key_1 = RSA.generate(1024)
public_key_1  = private_key_1.publickey()

M = "Hello World."

encrypted_message = public_key_1.encrypt(M, 24)
# print binascii.hexlify(encrypted_message[0])

# The private key corresponding to the public key used
# to encrypt the message can decrypt the message.
decrypted_message = private_key_1.decrypt(encrypted_message)
print decrypted_message

# The message can not be decrypted with another
# private key.
private_key_2 = RSA.generate(1024)
print private_key_2.decrypt(encrypted_message)

0 个答案:

没有答案