Hi Pearu,<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br>>>> import pickle<br>>>> from Crypto.Cipher import AES<br>
>>> cipher = AES.new('mysecret'*2)<br>
>>> dump=pickle.dumps(cipher)<br>PicklingError: Can't pickle '_AES' object: <_AES object at 0x1fe0bd0><br><br></div><div>I wonder if there are any fundamental reasons why pickling cipher objects cannot<br>
be pickled? Otherwise I would look into implementing pickling support for cipher objects.<br><br></div>I would presume that storing cipher object is safer (would it be?)<br><div>than storing an encryption key used to create the cipher object.<br>
</div></div></blockquote><div><br>Pickling a cipher object is actually less secure.<br><br>First, it cannot be more secure because anybody can easily find back the key from the pickled blob.<br><br>Second - and with the only exception of ECB mode - a cipher object is always stateful: it depends on the key, but also on the IV/nonce, and on the data you have processed so far. Pickling will make only sense if the encryption process has to be paused half-way so tat it can be resumed at a later moment. Not really a common use case.<br>
<br>Pickling a cipher and reusing later for a totally different encryption will lead to IV/nonce reuse, which is definitely bad, especially for stream cipher-like modes.<br></div></div>