Answer the question
In order to leave comments, you need to log in
How to decode it?
Hello. I am writing here with the last hope. I installed the pycryptodome library, as I am trying to make a client-server application, I will use AES from the library to ensure the security of information. Everything would be fine, but in order to encrypt a text that is a String, you need to put it in front of the text b'hello, world'
Then AES accepts it and encrypts it, at the moment after the cipher I get b'\x06\xad\x13*V\x01\xa55\xb6v}K'
After decoding b'\xfc\x0f%\xc9\x9f\x0f\x99\x17^\x16\x96\xd6'
But when I try to decode it back to text .decode('utf-8') I get
this error
decrypt = decrypt.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 0: invalid start byte
decrypt = decrypt.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xeb in position 0: invalid continuation byte
text = b'Hello, World'
AESkey = get_random_bytes(16)
def encrypt(message, key):
chiper = AES.new(key,AES.MODE_EAX)
crypt, tag = chiper.encrypt_and_digest(text)
return crypt, tag
def decrypt(message, key,tag):
chiper = AES.new(key,AES.MODE_EAX)
print(message)
decrypt = chiper.decrypt(message)
print(decrypt)
decrypt = decrypt.decode('utf-8')
print(decrypt)
cryptmess, tag = encrypt(text, AESkey)
decrypt(cryptmess, AESkey,tag)
Answer the question
In order to leave comments, you need to log in
fundamental principle:
-
Installed the pycryptodome libraryif something does not work:
I didn't quite understand why. AES has nothing to do with it. Get_random_bytes(16) returns crooked bytes (b'v\x19\xae\xd6\xfe\x92\x1cj\x8b\x17\x9d\xb6\x01#\xf7!') Because of this, when encrypting and decrypting everything is crooked, but it's still not clear how to do it so that the bytes are generated normally
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question