0

I'm attempting to generate an AES key with Pycrypto but receive the following error:

TypeError: 'list' does not support the buffer interface

for the following statement:

aescipher = AES.new(mykey, AES.MODE_ECB)

mykey, is of type list and contains [1885434739, 825373440, 0, 0]

Does anyone know how I can convert mykey into the correct type for the AES.new function?

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
keekers
  • 33
  • 4
  • How did you obtain the list? The first argument to `AES.new` should be a string. – unutbu Jan 26 '13 at 17:22
  • @unutbu it comes from this function (which is working correctly) http://pastebin.com/KBzzadNu – keekers Jan 26 '13 at 17:25
  • 1
    I do not understand the intention behind using `str_to_a32`, but just on the basis of "plugging things in that fit", `aescipher = AES.new(bytes,AES.MODE_ECB)` might work. – unutbu Jan 26 '13 at 17:56
  • Please put code that is vital to answering the question in the question itself, keekers. Questions should be self contained. – Maarten Bodewes Jan 26 '13 at 18:11
  • @unutbu you're somewhat right, since i'm porting someone elses javascript code. i've fixed the problem now though using struct.pack() – keekers Jan 26 '13 at 18:11

1 Answers1

2

You should not supply any kind of list/array when creating an AES key. The raw key bytes are normally supplied using a byte array of keysize / 8 bytes. For AES, the only key sizes that are supported are 128, 192 and 256 bits or 16, 24 and 32 bytes respectively.

Note that padding keys until they fit may lead to major cryptographic vulnerabilities. So is using ECB mode instead of a more secure mode like CBC (or one that also provides authentication/integrity protection such as GCM of course).

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263