Padding/trimming problems using PHP and MySQL AES_DECRYPT()

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Padding/trimming problems using PHP and MySQL AES_DECRYPT()

Post by mecha_godzilla »

Hi,

I'm currently putting some scripts together to test what happens when you encrypt/decrypt data using PHP's AES-128 implementation via mcrypt(), when you use the MySQL implementation and when you use a combination of the two. I wanted to do this to make sure that there weren't any problems with padding, etc. The results so far are:

1. When encrypting and decrypting with PHP no manual padding or trimming is needed.

2. When encrypting and decrypting with MySQL no manual padding or trimming is needed.

3. When encrypting with PHP and decrypting with MySQL a series of NULL characters are appended to the end of the data.

4. When encrypting with MySQL and decrypting with PHP a series of "white square"? characters are appended to the end of the data. Not sure whether this will parse properly but the character copied from my output page looks like ◻

For situation #3, I can use trim() but I'm having problems with situation #4 - I can't tell what this character is or how to get rid of it.

Has anyone encountered this problem or know what the character is?

Thanks,

Mecha Godzilla
Post Reply