AES256 in PyCrypto
Sebastian 'lunar' Wiesner
basti.wiesner at gmx.net
Sun Jan 7 13:14:41 EST 2007
[ mirandacascade at yahoo.com <mirandacascade at yahoo.com> ]
>
> Marc 'BlackJack' Rintsch wrote:
>
>> `a` must be of length 32 for AES256. And the length of `plainText`
>> must be a multiple of 16 because it's a block cypher algorithm.
>
> Thank you. I have some follow up questions and 1 tangential question.
>
> Follow up question:
> Would it be correct to infer that:
> a) the AES.pyd extension module (plus whatever additional files
> within the PyCrypto package that it uses) has the capability to
> perform AES256 encryption?
> b) the AES256 encryption happens based on the characteristics of the
> input to the new() method...if the first argument has a length of 32,
> the result will be AES256-style encryption?
Since you are apparently unable to read to docstrings of this module, I
will give you a short hint: yes, pycrypto supports AES with 256 bit
keys.
> c) will AES256-style encryption also happen if the first argument to
> the new() method has a length that is a multiple of 32, e.g. 64?
Why didn't you try this? It would have answered your question:
[12]--> AES.new(os.urandom(64), AES.MODE_CBC, os.urandom(16))
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)
/home/lunar/<ipython console>
ValueError: AES key must be either 16, 24, or 32 bytes long
> Tangential question:
> Is there functionality available (either in the PyCrypto package or
> some other package) that generates an initialization vector that can
> be used as input to the new() method? What prompts this question is
> that the original posting referenced a snippet of C# code; some other
> related snippets I saw seemed to suggest that:
> a) a RijndaelManaged() class gets instantiated
> b) that class has a GenerateIV() method which appears to populate
> someting in a IV property
> c) the application that was employing the AES256 encryption made use
> of the left-most 16 characters of the IV property
> So, I was curious whether something analgous exists in the Python
> world.
os.urandom will be your friend...
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
More information about the Python-list
mailing list