homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Can't get aes encrypt to work

5+ Year Member

Msg#: 4274904 posted 9:55 pm on Mar 1, 2011 (gmt 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.




WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member

Msg#: 4274904 posted 4:36 am on Mar 9, 2011 (gmt 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?


5+ Year Member

Msg#: 4274904 posted 4:53 am on Mar 9, 2011 (gmt 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 :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved