SQL reference (MySQL and MariaDB dialects)

Encryption and hash functions

MD5, SHA1 and SHA2: the hash functions Raft DB has, and the encryption functions it does not have.

Raft DB implements the checksum functions below. They take the bytes of the text and return text.

Not supported yet: AES_ENCRYPT, AES_DECRYPT, COMPRESS, UNCOMPRESS, UNCOMPRESSED_LENGTH, RANDOM_BYTES, PASSWORD, ENCRYPT, ENCODE, DECODE, DES_ENCRYPT, DES_DECRYPT, CRC32C and the key-derivation functions. CRC32 is on Numeric functions; TO_BASE64 and FROM_BASE64 on String functions.

Account passwords are not hashed with these functions; see the chapter on security.

Summary of functions#

FunctionWhat it doesDialect
MD5Returns the MD5 checksum of str as 32 hexadecimal digits in lower case.MySQL and MariaDB
SHASynonym of SHA1.MySQL and MariaDB
SHA1Returns the SHA-1 checksum of str as 40 hexadecimal digits.MySQL and MariaDB
SHA2Returns the SHA-2 checksum of str.MySQL and MariaDB

MD5#

SQL
MD5(str)

Returns the MD5 checksum of str as 32 hexadecimal digits in lower case.

Example:

SQL
SELECT MD5('abc');

Result: 900150983cd24fb0d6963f7d28e17f72

SHA#

SQL
SHA(str)

Synonym of SHA1.

Example:

SQL
SELECT SHA('abc');

Result: a9993e364706816aba3e25717850c26c9cd0d89d

SHA1#

SQL
SHA1(str)

Returns the SHA-1 checksum of str as 40 hexadecimal digits.

Example:

SQL
SELECT SHA1('abc');

Result: a9993e364706816aba3e25717850c26c9cd0d89d

SHA2#

SQL
SHA2(str, hash_length)

Returns the SHA-2 checksum of str. Only the length 256 (and 0, the same) is supported; other lengths (224, 384, 512) give NULL.

Example:

SQL
SELECT SHA2('abc', 256);

Result: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

See also#