SHA2()
Function Description
The SHA2() encryption function is used to calculate the SHA2 hash value of the input string. The first parameter is the plaintext string to have. The second parameter indicates the required bit length of the result, and its value must be 224, 256, 384, 512 or 0 (equivalent to 256), corresponding to the SHA-224, SHA-256, SHA-384 and SHA-512 algorithms, respectively. NULL will be returned if the parameter is NULL or is not a legal value.
Function Syntax
> SHA2(str, hash_length)
Parameter definition
| Parameters | Description |
|---|---|
| str | Required parameters. String to calculate hash value |
| hash_length | Required parameters. Hash length. |
Example
mysql> select sha2("hello world", 384);
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| sha2(hello world, 384) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)
mysql> select sha2(null, 512);
+-----------------------+
| sha2(null, 512) |
+-----------------------+
| NULL |
+-----------------------+
1 row in set (0.00 sec)
mysql> select sha2("abc", 99);
+--------------------+
| sha2(abc, 99) |
+--------------------+
| NULL |
+--------------------+
1 row in set (0.00 sec)