MySQL DES_DECRYPT() function
DES_DECRYPT() function
MySQL DES_DECRYPT() function decrypts an encrypted string and returns the original string.
Syntax:
DES_DECRYPT(crypt_str, [key_str]);
Arguments:
| Name | Description |
|---|---|
| crypt_str | An encrypted string. |
| key_str | String to decrypt crypt_str. |
Syntax Diagram:
MySQL Version: 8.0
Example:
Code:
SELECT DES_DECRYPT(DES_ENCRYPT('mytext','mypassward'),'mypassward');
Explanation:
The above MySQL statement decrypts the encrypted string 'mytext' as specified in the argument and returns the original string.
Output:
mysql> SELECT DES_DECRYPT(DES_ENCRYPT('mytext','mypassward'),'mypassward');
+--------------------------------------------------------------+
| DES_DECRYPT(DES_ENCRYPT('mytext','mypassward'),'mypassward') |
+--------------------------------------------------------------+
| mytext |
+--------------------------------------------------------------+
1 row in set (0.01 sec)
Example of MySQL des_decrypt() function using table
Sample table: testtable
| description |
|---|
| ^[@ú~,Iš‡Ýy |
| Oœ??^]Z_¦_<m |
| ˜¯(o 2¤®QЦ”jD,=ET£9Z! |
| ^[@£~,IsØY?y |
| Oo??^]Z_Ý_<m |
| ~_(o 2rQSÝ"jD,=ETœ9Z! |
| ^[@ú~,Iš‡Ýy |
Code:
SELECT description,DES_DECRYPT(description,'mydespassw')
FROM testtable;
Explanation:
The above MySQL statement retrieves the decrypted data from encrypted 'description' column from 'testtable'.
Output:
PREV : DECODE()
NEXT : DES_ENCRYPT()
