_randfunc attribute with a pickled rsa key
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Python-Crypto |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
I try to save and restore private key in file. So i use pickle module. And then when i crypt a message with dumped private key and when i try to decrypt it, pycrypto answer "_RSA object has not _randfunc attribute"
After long exam, i find problem from pickle module. So i write a little code exam like this
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from Crypto import Random
from Crypto.PublicKey import RSA
import pickle
rng=Random.
key=RSA.
print dir(key)
print dir(pickle.
And the result:
['__doc__', '__eq__', '__getattr__', '__getstate__', '__init__', '__module__', '__ne__', '__repr__', '__setstate__', '_blind', '_decrypt', '_encrypt', '_randfunc', '_sign', '_unblind', '_verify', 'blind', 'can_blind', 'can_encrypt', 'can_sign', 'decrypt', 'encrypt', 'exportKey', 'has_private', 'implementation', 'key', 'keydata', 'publickey', 'sign', 'size', 'unblind', 'validate', 'verify']
['__doc__', '__eq__', '__getattr__', '__getstate__', '__init__', '__module__', '__ne__', '__repr__', '__setstate__', '_blind', '_decrypt', '_encrypt', '_sign', '_unblind', '_verify', 'blind', 'can_blind', 'can_encrypt', 'can_sign', 'decrypt', 'encrypt', 'exportKey', 'has_private', 'implementation', 'key', 'keydata', 'publickey', 'sign', 'size', 'unblind', 'validate', 'verify']
So effectively, the _randfunc attribute is not in second display.
The problem is same if i use copy.deepcopy().
Best regards
Thanks
Changed in pycrypto: | |
status: | New → Fix Committed |
The problem you mention has been fixed in a recent patch:
https:/ /github. com/dlitz/ pycrypto/ commit/ db52ac71e804e85 ace3edd772d2e78 055972ac2c
Still, I wouldn't use pickle in the first place.
Using exportKey() and importKey() is much more secure and robust.