Skip to content
Related Articles

Related Articles

MySQL | AES_ENCRYPT ( ) Function
  • Last Updated : 06 Nov, 2019

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 encrpyt 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 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :