Jump to: navigation, search

Mysql AES ENCRYPT

From w3cyberlearnings

Contents

MySQL AES_ENCRYPT Function

This function encrypts data using the Advanced Encryptiong Standard algorithm. The encoding can be 128 bit key length and can extend it up to 256 bit key. Encoding 128 bit key length is secure enough for most purposes.

Syntax AES_ENCRYPT

  • str: data or string to be encrypted by the AES
  • key_str: is the key used for encryption.
AES_ENCRYPT(str, key_str);

Example 1

mysql> SELECT AES_ENCRYPT('password','secret');
+----------------------------------+
| AES_ENCRYPT('password','secret') |
+----------------------------------+
| �Nǃ}7����b�VM̷                      | 
+----------------------------------+
1 row in set 

Example 2

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

Output

mysql> SELECT * FROM userpassword;
+----+----------+------------------+
| id | username | password         |
+----+----------+------------------+
|  1 | Bill     | �Nǃ}7����b�VM̷   | 
+----+----------+------------------+
1 row in set 

Related Links


Navigation
Web
SQL
MISC
References