AES_ENCRYPT()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Encrypts data using the AES algorithm with the given key.
USAGE
AES_ENCRYPT(text, key_string)
Argument Name | Description |
---|---|
| The string to encrypt |
| The encryption key to use |
DETAILS
AES_ENCRYPT()
is an encryption function that encrypts a string using the Advanced Encryption Standard (AES) and returns a binary string.
A NULL
is returned if any of the arguments is NULL
.
EXAMPLES
SET @result = HEX(AES_ENCRYPT(
'This is a test string to encrypt',
'This is the AES key to use'));
SELECT SUBSTRING(@result, 1, 32) AS Hex_Substring;
+----------------------------------+
| Hex_Substring |
+----------------------------------+
| C3448D2B75B4C4F32221F78B7098FCBE |
+----------------------------------+
SET @key_str = SHA2('passphrase', 512);
SELECT HEX(AES_ENCRYPT('hello', @key_str))
AS Hex_String;
+----------------------------------+
| Hex_String |
+----------------------------------+
| B8656AA940B6D6ABAD5DA4891E746ED9 |
+----------------------------------+