V
V
Vincent2019-04-25 18:34:50
Python
Vincent, 2019-04-25 18:34:50

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

Sometimes this
decrypt = decrypt.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xeb in position 0: invalid continuation byte

(After encryption b'\xb3\xfa#\x06\xb6\xa6\xc5\x95F|CJ' ; After decryption b'\xeb`\xdb\x9bK|\xb25!\x18\xb4Z')
Maybe someone knows what case? Google, Yandex did not give clear results, and there is nothing about this in the documentation ...
I wanted to, but I forgot to insert all the code
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

2 answer(s)
#
#, 2019-04-25
@mindtester

fundamental principle:
-

Installed the pycryptodome library
if something does not work:
- read the documentation
- then look for feedback channels (and they exist - https://github.com/Legrandin/pycryptodome/issues)
- get help on third-party resources (like here) it's a matter of luck. possibly very large. it depends on the popularity of the library

V
Vincent, 2019-04-25
@wintreist

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 question

Ask a Question

731 491 924 answers to any question