I am using pycrypto to encrypt and decrypt a message using a key. I followed some examples and finally wrote my own. But it turns out that the encrypted message is not in unicode or ascii. I need to store the encrypted message on a mysql database but I won't be able to store such a thing - Oք��fo�A?"���������Ϩ��w}�7
. What can I do about this? Do I need to modify my mysql database or there's some other way to use Crypto
?
Here is my code.
from Crypto.Cipher import AES
import random
mode = AES.MODE_CBC
def encryptor(key, message):
IV = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
encrypto = AES.new(key, mode, IV=IV)
crypt_message = encrypto.encrypt(message)
cipher = crypt_message + IV
return cipher
def decryptor(key, cipher):
IV = cipher[-16:]
decrypt_message = cipher[:-16]
decrpyto = AES.new(key, mode, IV=IV)
message = decrpyto.decrypt(decrypt_message)
return message