Outdated Version

You are viewing an older version of this section. View current production version.

SHA2

Hashes the given string or binary data using the secure hash algorithm, version 2. As of this writing (early 2015), SHA2 is considered secure for generating collision-resistant hashes.

Syntax

SHA2 ( plaintext, bitlen )

Arguments

  • plaintext: the data to hash.
  • bitlen: the size of the hash to create. Currently SingleStore DB supports only the values 256, 384, 512, and 0 (equivalent to 256).

Return Type

Lower case hexadecimal digits corresponding to the binary hash value.

Examples

select sha2('ohai', 0);
+------------------------------------------------------------------+
| sha2('ohai', 0)                                                  |
+------------------------------------------------------------------+
| e84712238709398f6d349dc2250b0efca4b72d8c2bfb7b74339d30ba94056b14 |
+------------------------------------------------------------------+

select sha2('ohai', 256);
+------------------------------------------------------------------+
| sha2('ohai', 256)                                                |
+------------------------------------------------------------------+
| e84712238709398f6d349dc2250b0efca4b72d8c2bfb7b74339d30ba94056b14 |
+------------------------------------------------------------------+

select sha2('ohai', 384);
+--------------------------------------------------------------------------------------------------+
| sha2('ohai', 384)                                                                                |
+--------------------------------------------------------------------------------------------------+
| 2e2f6fcb70ea17cb674d7ba268026e30bde4cbe7abd74adc80d47f56ab15a5cc3e4e11e661cc22075a5b3b111bcc9afb |
+--------------------------------------------------------------------------------------------------+

select sha2('ohai', 512);
+----------------------------------------------------------------------------------------------------------------------------------+
| sha2('ohai', 512)                                                                                                                |
+----------------------------------------------------------------------------------------------------------------------------------+
| c8bd85242ad59306e2f5cd0f26c44408bf4e9a7c6b6f3f8317fd226bd131435400eff8de7b5f9927ea4aa4c0624cdd3a23630b1b5ab76207adae442e019284e5 |
+----------------------------------------------------------------------------------------------------------------------------------+

Related Topics