Search code examples
javapythonaespycrypto

How can I specify an AES key in Python?


I'm working on converting a Java program into Python and part of its core networking uses AES encryption to handle packets going up and down the line. Java's AES is initialized like so:

byte[] key = { 0x13, 0x00, 0x00, 0x00 };
sKeySpec = new SecretKeySpec(key, "AES");

I want to do the same in Python, and will use PyCrypto, but I'm not sure how to initialize the above in it as it only allows string-based "secret keys."


Solution

  • Use a string then

    key = '\x13\x00\x00\x00'