Crypto.Cipher question

Joined
Jun 23, 2009
Messages
1
Reaction score
0
Good evening,

I have a MySQL (version 5.0.5 running on Ubuntu 8.04) database containing encrypted fields (the encryption was done using mysql's AES_ENCRYPT). The database is normally accessed by an application written in C++ and Qt. However, I also need to access the database thru a web server and I am getting started with django.

The encryption key is 16 characters long, and the encrypted fields are defined as VARBINARY(64) in mySql.

I have a djando view where I want to display the decrypted data. The decryption is performed by Python (version 2.5.2) using the library Crypto.Cipher (from Crypto.Cipher import AES).
Of course I use the same key in both applications.
I do have the following issues:
I can only decrypt the data using the paired method, ie. using AES_DECRYPT() where data was encrypted using the MySQL method, and decrypt the data where the encryption was done by Python. If I tried to use AES_DECRYPT on data encrypted by the python code, AES_DECRYPT() returns NULL.
Decrypting data using the library Crypto.Cipher (from Crypto.Cipher import AES), the decrypted sting is padded to a length of 16 (or multiple of). For example

decryptString: decryptedStr = Deborah length of string = 16
Subject's firstName = Deborah
Character i = 0 68
Character i = 1 101
Character i = 2 98
Character i = 3 111
Character i = 4 114
Character i = 5 97
Character i = 6 104
Character i = 7 9
Character i = 8 9
Character i = 9 9
Character i = 10 9
Character i = 11 9
Character i = 12 9
Character i = 13 9
Character i = 14 9
Character i = 15 9

In the case above, the string is padded with chr(9), but other strings are padded with LF, or something else. The python code is listed here

def decryptString( strToDecrypt):
aesObject = AES.new( 'Example of a key', AES.MODE_ECB)
decryptedStr = aesObject.decrypt( strToDecrypt)
print "decryptString: decryptedStr = ", decryptedStr, " length of string = ", len( decryptedStr);
return decryptedStr

Any suggestions on how I can mix the encryption/decryption of values using these two applications?

Thanks
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top