472,351 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 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 12379
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...
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...
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...
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...
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...
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...
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...
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...
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.