python - PyCrypto RSA and Pickle -


i'm working pycrpyto's rsa class:

from crypto.cipher import pkcs1_v1_5 crypto.publickey import rsa  message = 'to encrypted' key = rsa.generate(2048) cipher = pkcs1_v1_5.new(key) ciphertext = cipher.encrypt(message) 

that code runs fine, , i'm able decrypt ciphertext. however, need able serialize these ciphers. haven't had problem pickle-ing other pycrypto ciphers, aes, when try pickle rsa cipher run following error:

from crypto.cipher import pkcs1_v1_5 crypto.publickey import rsa import pickle  message = 'to 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 

is there can around -- serialization framework, different construction method rsa object, etc., or un-pickle-able object?

pickling works fine public key component, when comes whole key, _randfunc doesn't survive pickling. had come across same error when working on project. can fine more information here: https://github.com/google/oauth2client/issues/638

make use of pycrypto's importkey , exportkey functions, documentation can found here: https://www.dlitz.net/software/pycrypto/api/2.6/


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -