###前提・実現したいこと
PyCryptoのRSAを使って暗号化&復号化をしたいのですが以下のエラーの原因がわからず困っています。
###発生している問題・エラーメッセージ
AttributeError: 'bytes' object has no attribute '_randfunc'
###該当のソースコード
python
1from Crypto.Cipher import PKCS1_v1_5 2from Crypto.PublicKey import RSA 3 4def encryption(data): 5 rsa = RSA.generate(2048) 6 pub_key = rsa.publickey().exportKey() 7 cipher = PKCS1_v1_5.new(pub_key) 8 ciphertext = cipher.encrypt(data) 9 10def decryption(ciphertext): 11 rsa = RSA.generate(2048) 12 pri_key = rsa.exportKey() 13 cipher = PKCS1_v1_5.new(pri_key) 14 orig = cipher.decrypt(ciphertext) 15 16 17if __name__ == "__main__": 18 data = b'message' 19 print(encryption(data)) 20 ciphertext = encryption(data) 21 print(decryption(ciphertext)) 22
###試したこと
エラーで指定されている箇所を確認したのですが解決方法はわかりませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
python3.5.1, pycrypto2.6.1を使っています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/27 11:56
2017/05/30 09:39