Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Can't get aes encrypt to work

9:55 pm on Mar 1, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 23, 2009
posts: 54
votes: 0

I am trying to use AES_ENCRPYT to encrypt some sensitive data in a MySQL database which needs to be able to be decrypted to allow a user to update the data later.

I am using the below syntax in PHPMyAdmin initially but, while I get a 1 row(s) inserted message, the field value is blank - any idea what I am doing wrong?

INSERT INTO table (field_name) VALUES (AES_ENCRYPT('text','password'))

The table and field in question is configured as:

`id` int(5) NOT NULL auto_increment,
`field_name` varchar(200) NOT NULL,

I am using PHPMyAdmin version 3.3.9 with MySQL version 5.0.92 and PHP version: 5.2.6 on Linux.

4:36 am on Mar 9, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
votes: 0

If AES_DECRYPT() detects invalid data or incorrect padding, it returns NULL.

Perhaps there is a problem with phpmyadmin, not sure, though. Why don't you try it from the command-line MySQL client?
4:53 am on Mar 9, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 23, 2009
posts: 54
votes: 0

Thanks for replying - I did get this sorted so thought I should share in case it helps someone else!

The problem is the field type - AES_ENCRYPT will not work with VARCHAR, the field type needs to be set to BLOB. Once I changed all the fields to BLOB it now encrypts and decrypts great :)

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members