473,289 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

AES256 in PyCrypto

Attempting to determine whether the PyCrypto package has the capability
to perform AES256 encryption. I received the following C# snippet:

CryptoProvider provider = new CryptoProvider();
Encrypted_Type password = new Encrypted_Type();
password.EncryptedData = new EncryptedDataType();
password.EncryptedData.EncryptionMethod = new EncryptionMethodType();
password.EncryptedData.EncryptionMethod.Algorithm = "AES256-cbc";

and I was told that it was the setup code for code that later on
performs AES256 encryption. I'm assuming that setting the Algorithm
property is what informs the system as to the type of encryption to
perform. I included the above snippet as a reference point, because
I'm attempting to understand how to do something equivalent in Python.

Would the following Python code perform AES256 encryption on plainText
from Crypto.Cipher import AES
x = AES.new(a, AES.MODE_CBC, iv)
x.encrypt(plainText)

assuming:
a = the key value
iv = an initialization vector
?

If the above Python code does not perform AES256 encryption:
a) is there functionality within PyCrypto that allows one to perform
AES256 encryption?
b) if such functionality does not exist in PyCrypto, does it exist in
some other Python package?

Operating System: Windows XP
Vsn of Python: 2.4

Thank you.

Jan 7 '07 #1
5 12487
In <11**********************@s34g2000cwa.googlegroups .com>, mirandacascade
wrote:
Would the following Python code perform AES256 encryption on plainText
from Crypto.Cipher import AES
x = AES.new(a, AES.MODE_CBC, iv)
x.encrypt(plainText)

assuming:
a = the key value
iv = an initialization vector
?
`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.

Ciao,
Marc 'BlackJack' Rintsch
Jan 7 '07 #2

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?
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?

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.

Thank you.

Jan 7 '07 #3
[ mi************@yahoo.com <mi************@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)
Jan 7 '07 #4
Sebastian 'lunar' Wiesner wrote:
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.
Thank you for the information.

The material I consulted was:
a) the PyCrypto manual: http://www.amk.ca/python/writing/pycrypt/
b) the .py files that shipped with the PyCrypto package

Is a docstring is the text between the three consecutive quote
characters in a .py file? The reason for the question is that I looked
at the .py files that shipped with PyCrypto. Of the various .py files
that shipped with PyCrypto, there were two files (both __init__.py)
that contained information seemed to pertain to AES. The stuff between
the 3 consecutive quote chars in:
Crypto.__init__.py
Crypto.Cipher.__init__.py
make reference to AES, but I wasn't able to determine from what I read
if that was AES256.
Which .py file contain the docstrings that flesh out the information
summarized in the short hint?

Can docstrings be embedded within the .pyd extension modules as well?
Does the AES.pyd extension module have docstrings? How does one view
the docstrings in a .pyd file? When I reference AES from the
interactive of Pythonwin:
>>from Crypto.Cipher import AES
x = AES.new(
As soon as I type the '(' character, the IDE displays:
new(key, [mode], [IV]): Return a new AES encryption object

then when x gets instantiated, and the encrypt method gets called...
>>x.encrypt(
As soon as I type the '(' character, the IDE displays:
Encrypt the provided string of binary data

I'm guessing that what the IDE is displaying is the first line of what
may be multiple-line docstring that is embedded within the .pyd
extension module? Might there be more lines in the docstring?

Thank you.

Jan 7 '07 #5
At Sunday 7/1/2007 18:23, mi************@yahoo.com wrote:
>Is a docstring is the text between the three consecutive quote
characters in a .py file? The reason for the question is that I looked
See section 4.6 in the Python Tutorial - I strongly suggest you read
it (or any other introductory text like diveintopython)
>Can docstrings be embedded within the .pyd extension modules as well?
Yes - if the original module writer has provided it.
>x = AES.new(
As soon as I type the '(' character, the IDE displays:
new(key, [mode], [IV]): Return a new AES encryption object [...]
I'm guessing that what the IDE is displaying is the first line of what
may be multiple-line docstring that is embedded within the .pyd
extension module? Might there be more lines in the docstring?
I don't know which IDE are you using, but try typing "help(AES.new)"
or simply "help" (without quotes) in the interpreter.
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Haim Ashkenazi | last post by:
Hi I'm trying to compile pycrypto on windows. I've installed mingw and try to run the command 'python setup.py build -c mingw32 install' and I get this error: $ python setup.py build -c...
2
by: Carmine Noviello | last post by:
Hi, I want to say first of all that I'm totally a newbie in cryptography world. Is there someone can show me a simple example on how to use PyCrypto lib and RSA to encrypt large text file? I'm...
0
by: Fuzzyman | last post by:
The location of the prebuilt windows installer for PyCypto 2.0 (for python 2.4) has changed. Apologies for any confusion, this is because of a website reorganisation at Voidspace. The new...
11
by: dirvine | last post by:
Does anyone know if pycrypto is active at all. I have been browsing groups etc. for some info and have found entries from 2003 (latest) regarding some bits I was looking for in particular reference...
2
by: Mike Meng | last post by:
Hi all, I'm learning Twisted and downloaded pyOpenSSL and pycrypto win32 installer on http://twisted.sourceforge.net/contrib/ . But I find the lastest version are for Python 2.3. I try to...
13
by: luca72 | last post by:
Hello I have to make an easy operation but reading the pycrypto doc. a never see AES example I have to cript this key 'ea523a664dabaa4476d31226a1e3bab0' with the AES. Can you help me for make it...
2
by: Ning | last post by:
I'm trying to write an IM client which sends encrypted messages to the server. I tried to use pycrypto library, but when I came to 3DES cypher I was confused about the keysize to use. In the...
3
by: mirandacascade | last post by:
Operating system: Win XP Vsn of Python: 2.4 Situation is this: Required to calcluate a message digest. The process for calcluating the digest must use an SHA-256 algorithm. Questions: 1) Is...
0
by: yaipa | last post by:
I snipped this bit of code out of Andrew Kuchling 'pyCrypto' test fixture. Having a need to XOR Binascii Hex strings in my current project, I found it very helpful to cut down on a bit of code...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.