The hash
statement is used to generate a base-16 or base-64 encoded hash of data stored in a variable or named buffer.
hash sha256 [HMAC
key] target|{target}
as
result
[b16|b64]
hash md5
target|{target}
as
result
[b16|b64]
The hash
statement uses the contents of target as its input and places the final result into result. The SHA256 and MD5 hash algorithms are supported.
If target is surrounded with curly braces like {this}
then it is taken to be the name of a memory buffer and the contents of the buffer will be used as input. Otherwise, it is treated as the name of the variable, the value of which will be hashed.
By default the resulting hash is base-16 encoded and the result placed into the variable specified by the result argument.
result is the name of the variable to put the output into, and not a reference to the contents of that variable. This is why it is not ${result}
If the optional HMAC
key
arguments are provided when the hash type is sha256
then the secret in key will be used to generate an HMAC-SHA-256 result.
If the optional b64
argument is used (base64
may also be specified), then the result will be encoded using base-64.
The optional b16
(base16
may also be used) is provided for completeness, but need not be specified as this is the default encoding to use.
Running the script:
results in the following output: