Results 1 to 10 of 10

Thread: Aes_decrypt

  1. #1
    Join Date
    May 2011
    Posts
    4

    Aes_decrypt

    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.

  2. #2
    Join Date
    Apr 2011
    Posts
    7
    What does your code look like?

  3. #3
    Join Date
    May 2011
    Posts
    4
    Here is the code I am using to encrypt 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);
    and the code, which is on a separate web page, to decrypt it.

    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;
    	}
    I am trying to print out the decrypted string to see if it works.

  4. #4
    Join Date
    Apr 2011
    Posts
    7
    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.

  5. #5
    Join Date
    May 2011
    Posts
    4
    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.

  6. #6
    Join Date
    Apr 2011
    Posts
    7
    Are you actually getting the record?
    Try outputting other info such as the encrypted password in addition to the decrypted password.

  7. #7
    Join Date
    May 2011
    Posts
    4
    I modified the code.

    It only prints out something if I include a request other than the password

    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');
    	
    	
     	}
    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['PASS'];
    	echo AES_DECRYPT('$pass', '.salt');
    	
    	
     	}
    When I can get the unencrypted password to print, it looks like.

    Code:
    ��������������������
    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.

  8. #8
    Join Date
    Nov 2011
    Posts
    3
    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'];
     	}

  9. #9
    Join Date
    Nov 2011
    Posts
    3
    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");

  10. #10
    Join Date
    Nov 2011
    Posts
    3
    // 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");
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •