Hash a string.
hash-string produces by default a SHA256 hash of <string> (if
"digest" clause is not used), and stores the result into <result> which can be created with optional
"define". <result> is
allocated memory. You can use a different <digest algorithm> in
"digest" clause (for example
"SHA3-256"). To see a list of available digests:
openssl list -digest-algorithms
With
"binary" clause, the <result> is a binary string that may contain null-characters. With the default SHA256, it is 32 bytes in length, while for instance with SHA3-384 it is 48 bytes in length, etc.
Without
"binary" clause, the <result> is null-terminated and each binary byte is converted to two hexadecimal characters (
"0"-
"9" and
"a"-
"f"), hence <result> is twice as long as with
"binary" clause.
The actual length of <result> (regardless of whether
"binary" clause is used or not) can be obtained in the optional
"output-length" clause in <output length>, which can be created with optional
"define".
String
"hash" will have a hashed value of the given string, an example of which might look like
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":
hash-string "hello world" to define hash
Using a different digest:
hash-string "hello world" to define hash digest "sha3-384"
Producing a binary value instead of a null-terminated hexadecimal string:
hash-string "hello world" to define hash digest "sha3-384" binary output-length define outlen