generate-hash(2)generate-hash - Generate SHA1 or SHA256 hash or HMAC
n generate-hash [ "key" ] [ "data" ]
generate-hash computes the SHA256 hash value of the current buffer's content, as if it were written to file in its current state (i.e. the binary, line and file termination modes are taken into consideration). The hash is then turned into a hex string and the $result(5) variable is set to the resultant 64 byte string.
The numeric argument n is a bit based flag used to modify the default behaviour of the command, where the bits are defined as follows:
0x01
0x02
0x04
0x08
0x10
To calculate the hash of a string use:
2 generate-hash "Hello world"
After executing the SHA256 hash value will be stored in $result. To calculate a HMAC-SHA256 of a string use:
6 generate-hash "TheKey" "Hello world"
After executing $result will be set to 1804C1869D6DD76A9A8D00819E6F62E970D981F01FE805F927CF4E3BDF4AD95C.
When using an argument of 2 the data must be a plain text string which means it cannot contain a byte of value 0. If the hash of binary data is required then set bit 1 and convert to a hex-string or create a temporary buffer, enable rbin(2m) mode, insert the data as a hex string and then call generate-hash with no argument to calculate the buffer's hash.
When calculating the hash of a region, if binary(2m) or rbin(2m) modes are enabled then the whole of the region's first line is always included , as is the whole of the last line if the region's end point column is greater than 0. If neither of these modes are enabled then the cr(2m) and lf(2m) line termination modes are taken into account, as is the ctrlz(2m) end of file mode.
$result(5), binary(2m), rbin(2m), cr(2m), lf(2m), ctrlz(2m), buffer-mode(2), SHA1(3), SHA256(3), HMAC-SHA256(3).
(c) Copyright JASSPA 2025
Last Modified: 2024/05/08
Generated On: 2025/09/29