Search code examples
pythonencryptioncryptographypycryptodome

PyCryptodome- Hex values change when put into a byte array for encryption


I'm trying to encrypt hex values as an input for an AES encryption. However, to use .encrypt(), only bytes, bytearrays or memoryview is the accept data types. So, I've been using bytearray.fromhex() to convert my hex values into a byte array.

My issue is from 0x20 - 0x7e is that these hex values become their byte value. Meaning that the encryption becomes incorrect. Since for example instead of encrypting b'\x22' it encrypts b'"'. My data that must be pushed through is:

00
11
22
33
44
55
66
77
88
99
aa
bb
cc
dd
ee
ff

Is there anyway to get this to display as b'\x22' in the byte array rather than b'"'. - E.g., getting the hex values to display as themselves not byte value. Or, would this not affect the output at all?

I understand it might be a bit confusing to grasp what I mean. Any help is appreciated.


Solution

  • What you have observed pertains to display of bytes in python consider that

    print(b'"' == b'\x22')
    

    gives output

    True