我一直在尝试使用pycrypto中的RSA加密Python中的数据。我试图在这里按照指示:http://www.laurentluce.com/posts/python-and-cryptography-with-pycrypto/但这里是出来当我打电话enc_data = public_key.encrypt('abcdefgh', 32)
:如何使用pycrypto和RSA加密(和解密)数据?
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
enc_data = public_key.encrypt('abcdefgh', 32)
File "C:\Python35\lib\site-packages\Crypto\PublicKey\RSA.py", line 150, in encrypt
return pubkey.pubkey.encrypt(self, plaintext, K)
File "C:\Python35\lib\site-packages\Crypto\PublicKey\pubkey.py", line 75, in encrypt
ciphertext=self._encrypt(plaintext, K)
File "C:\Python35\lib\site-packages\Crypto\PublicKey\RSA.py", line 224, in _encrypt
return (self.key._encrypt(c),)
File "C:\Python35\lib\site-packages\Crypto\PublicKey\_slowmath.py", line 65, in _encrypt
return pow(m, self.e, self.n)
TypeError: unsupported operand type(s) for pow(): 'str', 'int', 'int'
预先感谢对这个问题的任何意见。
你为什么要使用RSA加密数据? – zaph
请不要使用教科书(unpadded)RSA,因为它非常不安全。看看['Crypto.Cipher.PKCS1_OAEP'](https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.PKCS1_OAEP-module.html)。 –