MongooseA text-based world full of questionable inventions.

All help topics · Link to this topic

Showing help on 'binary_hash'

Syntax: string_hash (STR string [, STR algo [, ANY binary]]) => STR
binary_hash (STR bin-string [, STR algo [, ANY binary]]) => STR

string_hash -- Returns a hexadecimal or binary hash string.
binary_hash -- Returns a hexadecimal or binary hash string.

Returns a string encoding the result of applying a cryptographic hash function to the contents of the string text or the binary string bin-string. By default, SHA256 is used and the result is a 64-character hexadecimal string. If algo is provided, it specifies the hashing algorithm to use. Supported algorithms are MD5, SHA1, SHA224, SHA256, SHA384, SHA512, and RIPEMD160. If binary is true, the raw binary hash is returned instead of hexadecimal text.

Note that the MD5 hash algorithm is broken from a cryptographic standpoint, as is SHA1. Both are included for interoperability with existing applications (both are still popular).

All supported hash functions have the property that, if

string_hash(x) == string_hash(y)

then, almost certainly,

equal(x, y)

This can be useful, for example, in certain networking applications: after sending a large piece of text across a connection, also send the result of applying string_hash() to the text; if the destination site also applies string_hash() to the text and gets the same result, you can be quite confident that the large text has arrived unchanged.