I'm encrypting some data to store in a database. The encryption needs to be 2 way. Rather than use bzip or base64, I'd like to use something that requires a key to retreive the data. The problem is, I need to store the encrypted string in a MySQL and/or Sqlite database, preferably in a varchar field rather than a blob.
The way I'm doing the encryption is like so:
Code:
thing = 'encrypt me'
thing = thing.rjust(16,' ')
key = 'some padded key '
obj=AES.new(key, AES.MODE_ECB)
encrypted_val = obj.encrypt(thing)
(and then later, I can do an obj.decrypt(encrypted_val))
which results in:
Code:
"\xbbs\rv\xf8'u\xf9_\x02\xde\xad\x93E9\xb4"
...as ouptput by ipython which I believe does some sort of conversion so I can view the data. If I try to print out the value to a standard terminal, I get something like:
Code:
obj.encrypt(thing): '�p�
�*���� l1y'
(assuming you can even see that)
and, when I try to read that data from the db, similar problems arise & it causes my tests to fail.
Is there a better method of keyable two way encryption that results in ascii chars?
Is there a way to convert the binary to ascii for storage (like how ipython displays it), then a way to convert that ascii back to binary for obj.decrypt()?