©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The AES_DECRYPT SQL Function in MySQL and MariaDB - Decrypt with AES-Algorithmus

AES_DECRYPTSyntax:AES_DECRYPT(String, Key)
Return value:CHAR
Function type:Encryption & Compression
Function Description

The AES_DECRYPT() function decrypts a "Binary string" with the given "Key" using the AES algorithm.

The return is a decrypted string or NULL if an error occurs.

If "Key" contains a numeric value, it is interpreted as a character string.

If "Binary string" contains no characters, NULL is returned.

If the value of the "Binary string" or "Key" argument is NULL, the AES_DECRYPT() function returns NULL.


The function AES_ENCRYPT() can be used for encryption.

SQL Examples for the AES_DECRYPT function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

select aes_decrypt(unhex('4AF21D11E66D5A9830B4297CFD7A78F6'), 'Key');
select aes_decrypt(unhex('F5646561ECA0A52CE14174A8CE4FFB47'), 789);
select aes_decrypt(unhex('C717530F41F320757B4AA1BFAF11C42E'), 'key');
    /* crypted empty String */

select aes_decrypt(unhex('4AF21D11E66D5A9830B4297CFD7A78F6'), 'Error');
select aes_decrypt(null'Key');
select aes_decrypt(unhex('4AF21D11E66D5A9830B4297CFD7A78F6'), null);

aes_decrypt(unhex('4AF21D11E66D5A9830B4297CFD7A78F6'), 'Key')
varchar(16) BINARY
Test
aes_decrypt(unhex('F5646561ECA0A52CE14174A8CE4FFB47'), 789)
varchar(16) BINARY
123456
aes_decrypt(unhex('C717530F41F320757B4AA1BFAF11C42E'), 'key')
varchar(16) BINARY
 
aes_decrypt(unhex('4AF21D11E66D5A9830B4297CFD7A78F6'), 'Error')
varchar(16) BINARY
NULL
aes_decrypt(null, 'Key')
varchar(0) BINARY
NULL
aes_decrypt(unhex('4AF21D11E66D5A9830B4297CFD7A78F6'), null)
varchar(16) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the AES_DECRYPT() function in MySQL and MariaDB databases

Both MySQL and MariaDB provide an AES_DECRYPT() function that is used to decrypt data that have been encrypted with the AES encryption algorithm. The function takes the encrypted data and a key as input and returns the decrypted value as a string. It is important to note that the AES encryption algorithm used by the function requires that the data has been encrypted using the corresponding AES_ENCRYPT() function with the same key, otherwise the decryption process will fail and the function returns NULL.

The feature is specific to MySQL and MariaDB and may not be available in other database systems.
ACOSADDDATEADDTIMEAES_DECRYPTAES_ENCRYPTANY_VALUEASCII

Further MySQL und MariaDB SQL Encryption & Compression

AES_ENCRYPTAES_ENCRYPT(String, Key)
More about AES_ENCRYPT Function

COMPRESSCOMPRESS(String)
More about COMPRESS Function

DECODEDECODE(Binary string, Password)
More about DECODE Function

DES_DECRYPTDES_DECRYPT(Binary string [, Key])
More about DES_DECRYPT Function

DES_ENCRYPTDES_ENCRYPT(String [, Key])
More about DES_ENCRYPT Function

ENCODEENCODE(String, Password)
More about ENCODE Function

ENCRYPTENCRYPT(String [, Salt])
More about ENCRYPT Function

FROM_BASE64FROM_BASE64(String)
More about FROM_BASE64 Function

MD5MD5(String)
More about MD5 Function

OLD_PASSWORDOLD_PASSWORD(String)
More about OLD_PASSWORD Function

PASSWORDPASSWORD(String)
More about PASSWORD Function

RANDOM_BYTESRANDOM_BYTES(Length)
More about RANDOM_BYTES Function

SHASHA(String)
More about SHA Function

SHA1SHA1(String)
More about SHA1 Function

SHA2SHA2(String, Length)
More about SHA2 Function

TO_BASE64TO_BASE64(String)
More about TO_BASE64 Function

UNCOMPRESSUNCOMPRESS(Binary string)
More about UNCOMPRESS Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the AES_DECRYPT SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer