All pages
Powered by GitBook
1 of 1

Loading...

SHA2

Calculate SHA-2 checksum. This function computes the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512).

Syntax

SHA2(str,hash_len)

Description

Given a string str, calculates an SHA-2 checksum, which is considered more cryptographically secure than its equivalent. The SHA-2 family includes SHA-224, SHA-256, SHA-384, and SHA-512, and the hash_len must correspond to one of these, i.e. 224, 256, 384 or 512. 0 is equivalent to 256.

The return value is a nonbinary string in the connection , determined by the values of the and system variables.

NULL is returned if the hash length is not valid, or the string str is NULL.

SHA2 only works if MariaDB is configured with .

Examples

This page is licensed: CC BY-SA / Gnu FDL

SHA-1
character set and collation
character_set_connection
collation_connection
TLS support
SELECT SHA2('Maria',224);
+----------------------------------------------------------+
| SHA2('Maria',224)                                        |
+----------------------------------------------------------+
| 6cc67add32286412efcab9d0e1675a43a5c2ef3cec8879f81516ff83 |
+----------------------------------------------------------+

SELECT SHA2('Maria',256);
+------------------------------------------------------------------+
| SHA2('Maria',256)                                                |
+------------------------------------------------------------------+
| 9ff18ebe7449349f358e3af0b57cf7a032c1c6b2272cb2656ff85eb112232f16 |
+------------------------------------------------------------------+

SELECT SHA2('Maria',0);
+------------------------------------------------------------------+
| SHA2('Maria',0)                                                  |
+------------------------------------------------------------------+
| 9ff18ebe7449349f358e3af0b57cf7a032c1c6b2272cb2656ff85eb112232f16 |
+------------------------------------------------------------------+