我一直在嘗試使用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)。 –