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:
- 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.
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
Please Login to comment...