Open In App
Related Articles

MySQL | AES_DECRYPT ( ) Function

Improve Article
Improve
Save Article
Save
Like Article
Like

The MySQL AES_DECRYPT function returns the original string after decrypting an encrypted string. It uses AES(Advanced Encryption Standard) algorithm to perform the decryption. The AES_DECRYPT function returns the decrypted string or NULL if it detects invalid data. 

The value returned by the AES_DECRYPT function is the original plaintext string encrypted using AES_ENCRYPT function. The AES_DECRYPT function accepts two parameters which are the encrypted string and a string used to decrypt the encrypted string. 

Syntax: 

AES_DECRYPT(encrypted_string, key_string)

Parameters Used:  

  • encrypted_string – It is used to specify the encrypted string.
  • key_string – It is used to specify the String which is used to decrypt encrypted_string.

Return Value: 
The AES_DECRYPT function in MySQL returns the original plaintext string encrypted using AES_ENCRYPT function. 

Supported Versions of MySQL: 

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1

Example-1: Implementing AES_DECRYPT function on a string. 

SELECT  
AES_DECRYPT(AES_ENCRYPT('ABC', 'key_string'), 'key_string'); 

Output:  

ABC 

Example-2: Implementing AES_DECRYPT function on a string with a combination of characters and integer values. 

SELECT  
AES_DECRYPT(AES_ENCRYPT('ABC123', 'key_string'), 'key_string'); 

Output:  

ABC123 

Example-3: Implementing AES_DECRYPT function on a bigger string. 

SELECT  
AES_DECRYPT(AES_ENCRYPT('geeksforgeeks', 'key_string'), 'key_string'); 

Output:  

geeksforgeeks 

Example-4: Implementing AES_DECRYPT function on a NULL string. 

SELECT  
AES_DECRYPT(AES_ENCRYPT(NULL, 'key_string'), 'key_string'); 

Output:  

NULL  
Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation course.

Last Updated : 14 Sep, 2021
Like Article
Save Article
Previous
Next
Similar Reads