16, 24, and 32 bytes long for -128-, -196-, and -256- modes respectively.
The initialization vector length is always 16 bytes (bytes in excess of 16 are ignored).
HMAC
Introduced in: v25.12.0 Computes the HMAC (Hash-based Message Authentication Code) for the given message using the specified hash algorithm and secret key. Supported hash algorithms:- blake2b512
- blake2s256
- md4
- md5
- md5-sha1
- mdc2
- ripemd (aliases: RIPEMD160, ripemd)
- ripemd160
- rmd160 (aliases: RIPEMD160, rmd160)
- sha1
- sha224
- sha256
- sha3-224
- sha3-256
- sha3-384
- sha3-512
- sha384
- sha512
- sha512-224
- sha512-256
- shake128
- shake256
- sm3
- ssl3-md5 (aliases: MD5, ssl3-md5)
- ssl3-sha1 (aliases: SHA1, ssl3-sha1)
- whirlpool
mode— Hash algorithm name (case-insensitive). Supported: md5, sha1, sha224, sha256, sha384, sha512.Stringmessage— Message to be authenticated.Stringkey— Secret key for HMAC.String
String
Examples
Basic HMAC-SHA256
Query
Response
Query
Response
Query
Response
aes_decrypt_mysql
Introduced in: v20.12.0 Decrypts data encrypted by MySQL’sAES_ENCRYPT function.
Produces the same plaintext as decrypt for the same inputs.
When key or iv are longer than they should normally be, aes_decrypt_mysql will stick to what MySQL’s aes_decrypt does which is to ‘fold’ key and ignore the excess bits of IV.
Supports the following decryption modes:
- aes-128-ecb, aes-192-ecb, aes-256-ecb
- aes-128-cbc, aes-192-cbc, aes-256-cbc
- aes-128-cfb128
- aes-128-ofb, aes-192-ofb, aes-256-ofb
mode— Decryption mode.Stringciphertext— Encrypted text that needs to be decrypted.Stringkey— Decryption key.Stringiv— Optional. Initialization vector.String
String
Examples
Decrypt MySQL data
Query
Response
aes_encrypt_mysql
Introduced in: v20.12.0 Encrypts text the same way as MySQL’sAES_ENCRYPT function does.
The resulting ciphertext can be decrypted with MySQL’s AES_DECRYPT function.
Produces the same ciphertext as the encrypt function for the same inputs.
When key or iv are longer than they should normally be, aes_encrypt_mysql will stick to what MySQL’s aes_encrypt does which is to ‘fold’ key and ignore the excess bits of iv.
The supported encryption modes are:
- aes-128-ecb, aes-192-ecb, aes-256-ecb
- aes-128-cbc, aes-192-cbc, aes-256-cbc
- aes-128-ofb, aes-192-ofb, aes-256-ofb
mode— Encryption mode.Stringplaintext— Text that should be encrypted.Stringkey— Encryption key. If the key is longer than required bymode, MySQL-specific key folding is performed.Stringiv— Optional. Initialization vector. Only the first 16 bytes are taken into account.String
String
Examples
Equal input comparison
Query
Response
Query
Response
Query
Response
Query
Response
decrypt
Introduced in: v20.12.0 This function decrypts an AES-encrypted binary string using the following modes:- aes-128-ecb, aes-192-ecb, aes-256-ecb
- aes-128-cbc, aes-192-cbc, aes-256-cbc
- aes-128-ofb, aes-192-ofb, aes-256-ofb
- aes-128-gcm, aes-192-gcm, aes-256-gcm
- aes-128-ctr, aes-192-ctr, aes-256-ctr
- aes-128-cfb, aes-128-cfb1, aes-128-cfb8
mode— Decryption mode.Stringciphertext— Encrypted text that should be decrypted.Stringkey— Decryption key.Stringiv— Initialization vector. Required for-gcmmodes, optional for others.Stringaad— Additional authenticated data. Won’t decrypt if this value is incorrect. Works only in-gcmmodes, for others throws an exception.String
String
Examples
Correctly decrypting encrypted data
Query
Response
Query
Response
encrypt
Introduced in: v20.12.0 Encrypts plaintext into ciphertext using AES in one of the following modes:- aes-128-ecb, aes-192-ecb, aes-256-ecb
- aes-128-cbc, aes-192-cbc, aes-256-cbc
- aes-128-ofb, aes-192-ofb, aes-256-ofb
- aes-128-gcm, aes-192-gcm, aes-256-gcm
- aes-128-ctr, aes-192-ctr, aes-256-ctr
- aes-128-cfb, aes-128-cfb1, aes-128-cfb8
mode— Encryption mode.Stringplaintext— Text that should be encrypted.Stringkey— Encryption key.Stringiv— Initialization vector. Required for-gcmmodes, optional for others.Stringaad— Additional authenticated data. It isn’t encrypted, but it affects decryption. Works only in-gcmmodes, for others it throws an exception.String
String
Examples
Example encryption
Query
Response
Query
Response
tryDecrypt
Introduced in: v22.10.0 Similar to thedecrypt function, but returns NULL if decryption fails when using the wrong key.
Syntax
mode— Decryption mode.Stringciphertext— Encrypted text that should be decrypted.Stringkey— Decryption key.Stringiv— Optional. Initialization vector. Required for-gcmmodes, optional for other modes.Stringaad— Optional. Additional authenticated data. Won’t decrypt if this value is incorrect. Works only in-gcmmodes, for other modes throws an exception.String
NULL if decryption fails. Nullable(String)
Examples
Create table and insert data
Query
Response