Menu

MariaDB SHA() Function

Learn that MariaDB SHA() is an alias for SHA1(), returns a 40-character hexadecimal digest, and is not suitable for password storage.

Posted on By Updated on
On this page

MariaDB SHA(str) is a synonym for SHA1(str). It returns the SHA-1 digest of str as a 40-character hexadecimal string, or NULL when str is NULL. See the official SHA1() documentation.

Syntax

SHA(str)

Examples

Calculate a digest:

SELECT SHA('Hello, World!');

The result is the same as SHA1('Hello, World!'):

0a0a9f2a6772942557ab5355d76af442f8f65e01

A NULL input returns NULL:

SELECT SHA(NULL);

SHA() and SHA1() are fast, general-purpose hash functions. Do not use them to store application passwords. For password storage, use a purpose-built password-hashing library such as Argon2id, bcrypt, or PBKDF2. See the OWASP Password Storage Cheat Sheet. For new non-password digests, see MariaDB’s SHA2() documentation.

Summary

SHA() is an alias for SHA1() and returns a 40-character SHA-1 digest. It is not encryption and is not a password-hashing function.