MySQL Forums
Forum List  »  Knowledge Base

Problem with aes_encrypt and aes_decrypt
Posted by: sobha muktha
Date: April 30, 2009 12:54AM

Hi

I am unable to encrypt the data using aes_encrypt

My code is below

CREATE TABLE IF NOT EXISTS `test` (
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

$password = "random";
$name = "fred";
$email = "fred@example.com";

mysql_query("INSERT INTO test (name, email) VALUES (AES_ENCRYPT('$name', '$password'), AES_ENCRYPT('$email', '$password'))");

$query = mysql_query("SELECT AES_DECRYPT(`name`, '$password') as name, AES_DECRYPT(`email`, '$password') as email FROM test");
while($r = mysql_fetch_array($query)) {
echo "-" . $r['name'] . "-" . $r['email'] . "<br>";
}


Please help me it is inserting in the database as empty or some special characters but aes_decrypt is returning null

My whole work is reading data from one table and inserting in another table in encrypted format.

Please suggest what i can do

Regards,
Sobhamuktha

Options: ReplyQuote


Subject
Views
Written By
Posted
Problem with aes_encrypt and aes_decrypt
5695
April 30, 2009 12:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.