Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading