My problem is that when I use pycryptodome for decrypting a string in Python 3.6 with the following code:
from Crypto.Cipher import AES
from Crypto import Random
key = "133BBB3212332231"
key_bytestring = key.encode("utf-8")
iv = Random.new().read(AES.block_size)
cipher = AES.new(key_bytestring, AES.MODE_CFB, iv)
encrypted_string = 'ý\x82iq\x193\x1aÙË\x04Û£¥\x8dbBOW}Vû\x01\x86zÕ¼Ó)áôO\x14'
encrypted_bytes = encrypted_string.encode("utf-8")
decrypted_bytes = cipher.decrypt(encrypted_bytes)
decrypted_string = decrypted_bytes.decode("utf-8")
print(decrypted_string )
Python throws this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 1: invalid start byte
In this line:
decrypted_string = decrypted_bytes.decode("utf-8")
I'm updating some code from Python 2.7, and pycrypto has changed to pycryptdodome. In python 2.7 this works like a charm with pycrypto(I've invented the key so the string is not decrypted well but Python don't throw any error):
from Crypto.Cipher import AES
from Crypto import Random
key = "133BBB3212332231"
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CFB, iv)
encrypted_string = 'ý\x82iq\x193\x1aÙË\x04Û£¥\x8dbBOW}Vû\x01\x86zÕ¼Ó)áôO\x14'
decrypted_string = cipher.decrypt(encrypted_string)
print(decrypted_string)
How can I fix this? I'm quite desperate, since I've been trying it for a long time and I did't come to anything. Thank you in advance!