Jump to: navigation, search

Mysql DES ENCRYPT

From w3cyberlearnings

Contents

MySQL DES_ENCRYPT Function

This function encrypts a string with the given key using the Triple-DES algorithm.

Syntax DES_ENCRYPT

  • str: string to encrypt
  • key_str: string use as key string for encrypt str
DES_ENCRYPT(str, key_str);

Note

String length for the result= orig_len + (8 - (orig_len % 8)) + 1

Example 1

mysql> SELECT DES_ENCRYPT('great holiday');
+------------------------------+
| DES_ENCRYPT('great holiday') |
+------------------------------+
| ������L��∍Qj            | 
+------------------------------+
1 row in se

Example 2

Use Different key

mysql> SELECT DES_ENCRYPT('great holiday','god');
+------------------------------------+
| DES_ENCRYPT('great holiday','god') |
+------------------------------------+
| ��(���(��@]�c���)                  | 
+------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT DES_ENCRYPT('great holiday','kc');
+-----------------------------------+
| DES_ENCRYPT('great holiday','kc') |
+-----------------------------------+
| ����)P,�H��l�y��	                 | 
+----------------------

Example 3

mysql> INSERT INTO userpassword
    -> (username,password)
    -> VALUES('Sokha',DES_ENCRYPT('good','kk'));
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM userpassword WHERE password=DES_ENCRYPT('good','kk');
+----+----------+-----------+
| id | username | password  |
+----+----------+-----------+
|  1 | Sokha    | ������S�� | 
+----+----------+-----------+
1

Related Links


Navigation
Web
SQL
MISC
References