I'm trying to use pyaes (https://github.com/ricmoo/pyaes/blob/master/README.md) in Python 3 to encrypt and decrypt text using pyaes. When I encrypt text, I give pyaes a str
value i.e.
plaintext = 'plain text'
key = os.urandom(16)
aes = pyaes.AESModeOfOperationCTR(key)
ciphertext = aes.encrypt(plaintext)
when I decrypt though, I get back a bytes
type:
aes = pyaes.AESModeOfOperationCTR(key)
decrypted_plaintext = aes.decrypt(ciphertext)
Printing decrypted_plaintext
produces the following output, which seems to contain the original text:
b'plain text'
But its not quite the same; one is a str
the other is a bytes
:
plaintext == decrypted_plaintext # False
I'm struggling to understand the relationship between bytes
and whatever Python 3's internal representation of str
is. How do I convert the bytes
type into str
to get my plaintext?
I have confirmed that running the examples on the pyaes readme page have the same problem. I'm guessing that is going to be something to do with encodings.