mariadb-encryption-functions

Catalogs MariaDB encryption, hashing, and compression functions with signatures and version-specific behavior.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-encryption-functions-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-encryption-functions
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/functions/mariadb-encryption-functions
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-encryption-functions-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing SQL that encrypts, hashes, or compresses data in MariaDB is error-prone: AES_ENCRYPT defaults to deterministic ECB mode, binary results get mangled in TEXT columns, and functions like DES_ENCRYPT were removed in MariaDB 13.0. This Skill provides a version-aware reference so generated SQL avoids these pitfalls. ## Core Features & Use Cases - Complete function catalog: Signatures and one-line semantics for all 17 built-in encryption, hashing, and compression functions, from AES_ENCRYPT/AES_DECRYPT to KDF, RANDOM_BYTES, SHA2, and COMPRESS/UNCOMPRESS. - Common mistake corrections: A table of LLM pitfalls, such as assuming AES_ENCRYPT uses a random IV by default, storing binary output in VARCHAR, or treating PASSWORD(NULL) as NULL-propagating. - Version gating: Annotations marking functions available only since specific releases (RANDOM_BYTES since 10.10, KDF since 11.3, IV/mode args since 11.2) and removals in 13.0. - Use Case: When asked to write a query that encrypts a column, the Skill guides you to use AES_ENCRYPT with an explicit IV from RANDOM_BYTES(16) and mode 'aes-256-cbc', storing the result in a VARBINARY column. ## Quick Start Write a MariaDB query that encrypts user email addresses with AES-256-CBC and stores the result safely.

Frequently Asked Questions about mariadb-encryption-functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use AES_ENCRYPT with an IV in MariaDB?▼

Pass an explicit IV and mode as the third and fourth arguments, for example AES_ENCRYPT(str, key, iv, 'aes-256-cbc'), available since MariaDB 11.2. Generate the IV with RANDOM_BYTES(16); without these arguments the function uses the block_encryption_mode variable, which defaults to deterministic aes-128-ecb.

Which MariaDB function should I use for password hashing?▼

Use SHA2() for one-way hashing or KDF() for a slow, brute-force-resistant key derivation. MD5() and SHA1() are checksums with known vulnerabilities, and PASSWORD() is meant only for server authentication strings in SET PASSWORD or CREATE USER statements.

Why does AES_DECRYPT return garbage instead of an error in MariaDB?▼

AES_DECRYPT returns NULL only when it detects invalid data or incorrect padding. With a wrong key or a cipher mode mismatch, such as encrypting with CBC and decrypting with ECB, it can return a non-NULL garbage string silently.

Does MariaDB 13.0 still support DES_ENCRYPT and ENCODE?▼

DES_ENCRYPT and DES_DECRYPT were removed in MariaDB 13.0 along with the --des-key-file option, so migrate to AES_ENCRYPT and AES_DECRYPT. ENCODE and DECODE were not removed but are documented as not cryptographically secure.

Why does SHA2 return NULL on my MariaDB server?▼

SHA2 returns NULL for an invalid hash_len (must be 224, 256, 384, 512, or 0), a NULL input, or when the server was built without TLS/SSL support, since it relies on the SSL library's SHA implementation unlike MD5 and SHA1.

What column type should store AES_ENCRYPT output in MariaDB?▼

Store AES_ENCRYPT, COMPRESS, RANDOM_BYTES, and KDF output in VARBINARY or BLOB columns because all four return binary strings. Using CHAR, VARCHAR, or TEXT mangles the result through charset conversion and trailing-space trimming.