MySQL AES_Encrypt / AES_Decrypt

Discussion in 'PHP' started by jsamdirect, May 19, 2009.

  1. #1
    I am trying to store data in a MySQL 4 table using aes. I can insert the data ok but any time I try to select it with aec_decrypt it returns null / blank.

    I have tried different data types, varchar, varbinary, text, blob, but nothing seems to work. Note that if I set it to binary, MySQL auto changes it to varbinary. If I set it to anything other then varbinary the data does not get inserted into the table. Note sure why that is. I am sure the aes password is correct.

    Here is an example of the query:
    SELECT AES_DECRYPT(password, 'AESPassword') FROM users WHERE uid='user'

    while($row = mysql_fetch_array($result))
    {
    echo $row['password'];
    echo "<br />";
    }

    Any thoughts on what I am missing?
     
    jsamdirect, May 19, 2009 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    use echo $row[0]; instead of echo $row['password'];
    Regards
     
    koko5, May 19, 2009 IP
  3. jsamdirect

    jsamdirect Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That worked!!! Thanks!!!!!!
     
    jsamdirect, May 19, 2009 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    Glad to hear that :)

    Note that if you want to use assoc you can do something like this:
    and than you echo $row['BLA'];
    aliases save you lot of typing, otherwise you have to
    echo $row['AES_DECRYPT(password, "AESPassword")'] because this is column name.

    Regards
     
    koko5, May 19, 2009 IP
  5. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    A quick tip, if you are unsure what the array value is for a returned item, you can use:

    print_r($row); inside your while statement and it will show you the contents of the variable in its recursive format.
     
    NatalicWolf, May 19, 2009 IP