Skip to content
Related Articles
Open in App
Not now

Related Articles

MySQL | AES_ENCRYPT ( ) Function

Improve Article
Save Article
  • Last Updated : 25 Aug, 2021
Improve Article
Save Article

The MySQL AES_ENCRYPT function is used for encrypting a string using Advanced Encryption Standard (AES) algorithm. The MySQL AES_ENCRYPT function encodes the data with 128 bits key length but it can be extended up to 256 bits key length. It encrypts a string and returns a binary string. 

The value returned by the AES_ENCRYPT function is a binary string or NULL if the argument in NULL. The AES_ENCRYPT function accepts two parameters which are the encrypted string and a key string used to encrypt the string. 


AES_ENCRYPT(str, key_str)

Parameters Used:  

  • str – It is used to specify the plain string.
  • key_str – It is used to specify the String which is used to encrypt the str.

Return Value: 
The AES_ENCRYPT function in MySQL returns a binary string. 

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_ENCRYPT function on a string.  

AES_ENCRYPT('ABC', 'key'); 



Example-2: Implementing AES_ENCRYPT function on a bigger string.  

AES_ENCRYPT('geeksforgeeks', 'key'); 



Example-3: Implementing AES_ENCRYPT function on a NULL string.  



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!