| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
|Subscribe and Support WebmasterWorld|
|Can't get aes encrypt to work|
| 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:
CREATE TABLE IF NOT EXISTS `table` (
`id` int(5) NOT NULL auto_increment,
`field_name` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=28 ;
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)|
|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)|
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 :)
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved