hash-string
Purpose: Hash a string.
hash-string <string> to [ define ] <result> \
[ binary [ <binary> ] [ output-length [ define ] <output length> ] \
[ digest <digest algorithm> ]
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
If "binary" clause is used without optional boolean expression <binary>, or if <binary> evaluates to true, then 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, or if <binary> evaluates to false, 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".
Examples
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
See also
Encryption (
decrypt-data derive-key encrypt-data hash-string random-crypto random-string )
SEE ALL (
documentation)