hash()
The hash() function computes the hash value of binary data using a specified hash algorithm and returns it as binary.
Syntax
hash(ALGORITHM, DATA)
Parameters
ALGORITHM- The name of the hash algorithm. Specify one of
md5,sha1,sha256,sha384, orsha512. DATA- The binary data to hash.
Description
The hash() function computes the hash value of binary data using the specified hash algorithm and returns it as binary.
Returns null if DATA is null or not a binary type.
An error is raised at query parse time if an unsupported algorithm is specified or if required parameters are missing.
Error codes
| Error code | Description |
|---|---|
| 90690 | No hash algorithm was specified. |
| 90691 | No hash data was specified. |
| 90692 | An unsupported hash algorithm was specified. |
Usage examples
-
Compute the MD5 hash value
json "{}" | eval result = tohex(hash("md5", encode("hello, world!"))) | # result: 3adbbad1791fbae3ec908894c4963870 -
Compute the SHA-256 hash value
json "{}" | eval result = tohex(hash("sha256", encode("hello, world!"))) | # result: 68e656b251e67e8358bef8483ab0d51c6619f3e7a1a9f0e75838d41ff368f728 -
Non-binary value as input
json "{}" | eval result = hash("md5", "hello world") | # result: null -
DATAisnulljson "{}" | eval result = hash("sha1", null) | # result: null
Compatibility
The hash() function has been available since before Sonar 4.0.