MySQL AES_DECRYPT() function
AES_DECRYPT() function
MySQL AES_DECRYPT() function decrypts an encrypted string using AES algorithm to return the original string. It returns NULL if detects invalid data.
Syntax:
AES_DECRYPT(crypt_str, key_str);
Arguments:
Name | Description |
---|---|
crypt_str | An encrypted string. |
key_str | String to use to decrypt crypt_str. |
Syntax Diagram:
MySQL Version: 8.0
Example:
Code:
SELECT AES_DECRYPT(AES_ENCRYPT('mytext','mykeystring'),
'mykeystring');
Explanation:
The above MySQL statement decrypts the encrypted string 'mytext' using mykeystring and returns the original string mytext.
Output:
mysql> SELECT AES_DECRYPT(AES_ENCRYPT('mytext','mykeystring'),'mykeystring'); +----------------------------------------------------------------+ | AES_DECRYPT(AES_ENCRYPT('mytext','mykeystring'),'mykeystring') | +----------------------------------------------------------------+ | mytext | +----------------------------------------------------------------+ 1 row in set (0.00 sec)
Sample table: testtable
Code:
SELECT description, AES_DECRYPT(description,'passw')
FROM testtable;
Explanation:
The above MySQL statement retrieves the decrypted data from encrypted 'description' column from 'testtable'.
Output:
mysql> SELECT description, AES_DECRYPT(description,'passw') -> FROM testtable; +---------------------------+----------------------------------+ | description | AES_DECRYPT(description,'passw') | +---------------------------+----------------------------------+ | ^5[@·˜,IÜç¦Éý | mytext | | Ô£^]Žþª_‹m | NULL | | ÿ»(õ 2ñ«QèªöjD¸=ËTú9Ž! | NULL | +---------------------------+----------------------------------+ 3 rows in set (0.04 sec)
Previous: YEARWEEK()
Next: AES_ENCRYPT()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/mysql/encryption-and-compression-functions/aes_decrypt().php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics