Search code examples
mysqlsqlaes

Mysql AES_Decrypt from multiple columns


I am trying to use AES_DECRYPT to decrypt multiple columns from a table, how can I do that?

What I am trying:

SELECT column_a, column_b, column_c AES_DECRYPT(column_a, column_b, column_c 'p4ss0wrd1') 
FROM dates_table1;

Could someone guide me thru the right syntax? Or if its possible to decrypt everything directly from a table.


Solution

  • The AES_DECRYPT function only accepts one value at a time (I mean one encrypted string, plus the password). Also, if the values were encrypted separately then it makes no sense to try and decrypt them all as one thing.

    Just call the function separately for each column:

    SELECT 
      column_a, 
      column_b, 
      column_c, 
      AES_DECRYPT(column_a, 'p4ss0wrd1'),
      AES_DECRYPT(column_b, 'p4ss0wrd1'),
      AES_DECRYPT(column_c, 'p4ss0wrd1')
    FROM 
      dates_table1;
    

    Documentation: https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_aes-decrypt