Open In App

MySQL | AES_ENCRYPT ( ) Function

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. 



Syntax:  

AES_ENCRYPT(str, key_str)

Parameters Used:  



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

Supported Versions of MySQL: 
 

Example-1: Implementing AES_ENCRYPT function on a string.  

SELECT
AES_ENCRYPT('ABC', 'key'); 

Output:  

\\YJ??f&K?M?q?* 

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

SELECT 
AES_ENCRYPT('geeksforgeeks', 'key'); 

Output:  

2G???B?????*?? 

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

SELECT  
(AES_ENCRYPT(NULL, 'key'); 

Output: 

NULL 
Article Tags :
SQL