I managed to encrypt a string (Password) with AES_ENCRYPT but I am having difficulty decrypting it. I am using PHP and running MySQL. Any help is appreciated.
Printable View
I managed to encrypt a string (Password) with AES_ENCRYPT but I am having difficulty decrypting it. I am using PHP and running MySQL. Any help is appreciated.
What does your code look like?
Here is the code I am using to encrypt it
and the code, which is on a separate web page, to decrypt it.Code:if(!define('SALT'))
define('SALT','n7g7b8necefAs5ecrEv3M72ra');
$pwd=$_POST['pass'];
$ins="INSERT INTO accounts (FirstName, LastName, School, Email, PASS)
VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[school]', '$_POST[email]', AES_ENCRYPT('$pwd','.salt'))";
mysql_query($ins, $con);
I am trying to print out the decrypted string to see if it works.Code:if(!define('SALT'))
define('SALT','n7g7b8necefAs5ecrEv3M72ra');
$result = mysql_query("SELECT * FROM accounts");
while($row = mysql_fetch_array($result))
{
$pass = $row['PASS'];
$une = AES_DECRYPT('$pass', '.salt');
echo $une;
}
What results are you getting? Errors? No output?
I'm not a coder, but now that you've posted the source another member may be able to debug your code.
There is no output at all. I know it's encrypting because I can login to my SQL database and see the encrypted data. I just cant seem to decrypt it.
Are you actually getting the record?
Try outputting other info such as the encrypted password in addition to the decrypted password.
I modified the code.
It only prints out something if I include a request other than the password
It prints out nothing if I exclude the echo $row['EMAIL'];Code:if(!define('SALT'))
define('SALT','n7g7b8necefAs5ecrEv3M72ra');
$result = mysql_query("SELECT * FROM accounts");
while($row = mysql_fetch_array($result))
{
echo $row['EMAIL'];
echo $row['PASS'];
echo AES_DECRYPT('$pass', '.salt');
}
When I can get the unencrypted password to print, it looks like.Code:if(!define('SALT'))
define('SALT','n7g7b8necefAs5ecrEv3M72ra');
$result = mysql_query("SELECT * FROM accounts");
while($row = mysql_fetch_array($result))
{
echo $row['PASS'];
echo AES_DECRYPT('$pass', '.salt');
}
And even then it's only printing out the first row of data, it doesn't print out any of the other information in the table.Code:��������������������
iv been playing with this alsp
Code:if(!define('SALT'))
define('SALT','n7g7b8necefAs5ecrEv3M72ra');
$salt = SALT;
// from my understanding so far , you can't use a wild card in the select because AES_DECRYPT needs to be called inside the query. MySQL is actually doing the processing not PHP.
$result = mysql_query("SELECT id,username,AES_DECRYPT('password','$sql') FROM accounts");
while($row = mysql_fetch_array($result))
{
//now heres the problem Im running into. When the data is returned it looks like this :
echo $row['AES_DECRYPT(password,n7g7b8necefAs5ecrEv3M72ra)'];
//I really need it to come back like: $row['oassword'];
}
Ok great and I found the answer to my problem now, lol At least one of them.
http://www.daniweb.com/web-developme...60#post1700560
Code:$result = mysql_query("SELECT id,username,AES_DECRYPT('password','$sql') as password FROM accounts");
// heres the way it needs to be I think
if(!define('SALT'))
define('SALT','n7g7b8necefAs5ecrEv3M72ra');
$salt = SALT;
// from my understanding so far , you can't use a wild card in the select because AES_DECRYPT needs to be called inside the query. MySQL is actually doing the processing not PHP.
$result = mysql_query("SELECT id,username,AES_DECRYPT('password','$sql') as PASS FROM accounts");
}