나는 pyCrpyto의 RSA 클래스와 함께 일하고 있어요. 그러나, 나는이 암호를 serialize 할 수 있어야합니다. 내가 AES와 같은 다른 pyCrypto 암호를 -ing 문제 pickle
없었어요,하지만 난 pickle
에 RSA 암호를하려고 할 때 다음과 같은 오류로 실행PyCrypto RSA와 피클
from Crypto.Cipher import PKCS1_v1_5
from Crypto.PublicKey import RSA
import pickle
message = 'To be encrypted'
key = RSA.generate(2048)
cipher = PKCS1_v1_5.new(key)
pickle.dump(cipher, open("cipher.temp", "wb"))
cipher = pickle.load(open("cipher.temp", "rb"))
ciphertext = cipher.encrypt(message)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Crypto/Cipher/PKCS1_v1_5.py", line 119, in encrypt
randFunc = self._key._randfunc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Crypto/PublicKey/RSA.py", line 126, in __getattr__
raise AttributeError("%s object has no %r attribute" % (self.__class__.__name__, attrname,))
AttributeError: _RSAobj object has no '_randfunc' attribute
나는이 해결하기 위해 할 수있는 일이 있나요 다른 직렬화 프레임 워크, RSA 객체의 다른 구축 방법 등, 또는 이것은 단지 un-pickle
-able 객체입니까?
합니다. PyCrypto는 키를 내보내고 가져 오는 기능을 제공합니다. 너 그거 해봤 니? –
@ArtjomB. 나는 그것을 시도 할 것이지만 암호를 하나의 파일로 직렬화 할 수 있기를 희망했다. 그냥 키를 직렬화하고 (피클 리토가 아닌 PyCrypto의 내보내기를 사용하여) 시리얼을 가져온 다음 암호를 가져 와서 재구성하는 것이 좋습니다. – bkaiser