Jump to: navigation, search

Mysql AES DECRYPT

From w3cyberlearnings

Contents

MySQL AES_DECRYPT Function

This function decrypts data using Advanced Encryption Standard Algorithm.

Syntax AES_DECRYPT

  • crypt_str: encrypted string by AES_ENCRYPT.
  • key_str: descrypt key (this key must be the same as it used in the AES_ENCRYPT).
AES_DECRYPT(crypt_str,key_str);


Note

Password is 'password', and Secret key is 'secret'.

Insert Uses AES_ENCRYPT

mysql> INSERT INTO userpassword(username,password) 
    -> VALUES('Bill',AES_ENCRYPT('password','secret'));
Query OK, 1 row affected (0.00 sec)

Decrypt Uses AES_DECRYPT()

mysql> SELECT id, username, AES_DECRYPT(password,'secret') FROM userpassword;
+----+----------+--------------------------------+
| id | username | AES_DECRYPT(password,'secret') |
+----+----------+--------------------------------+
|  1 | Bill     | password                       | 
+----+----------+--------------------------------+
1 row in set (0.00 sec)

Find User Information based on the password

mysql> SELECT id,username FROM userpassword WHERE password=AES_ENCRYPT('password','secret');
+----+----------+
| id | username |
+----+----------+
|  1 | Bill     | 
+----+----------+
1 row in set (0.00 sec)

Related Links


Navigation
Web
SQL
MISC
References