Global Lua Modules/Hash

{{Infobox Lua
| Type = invocable
| Status = stable
| Description = Provides convenient wrappers around mw.hash for MD5.
| Author = Puxlit
| Code = Hash
| Examples = {{{examples|{{Ref/Name}} on Terra Formars Wiki}}}
}}
Hash provides convenient wrappers around mw.hash for MD5. Applications include generating predictable names to ref parser tags for automatic citation deduplication.
== ==
== ==
=== MD5 ===
To generate an MD5 hex digest from wikitext, invoke the md5_hexdigest function with one or more anonymous or numbered parameters. Note that named parameters (and numbered parameters that are disconnected from the sequence of anonymous or numbered parameters starting at 1) will be ignored. If there is more than one parameter, the input message is the concatenation of each parameter's value (in numeric key order) separated by a null byte. Bear in mind that leading and trailing spaces are preserved for anonymous parameter values, whereas they are stripped for numbered parameter values.
To generate an MD5 digest in your own module, call MD5 with an optional message to return an interface. From this interface, call update with additional message chunks as necessary. For convenience, this function returns the existing interface to permit method chaining. To finalize computation and obtain a digest, call (from the interface) either digest (for a binary string) or hexdigest (for a hex representation). Note that once finalized, subsequent calls to update will throw an error.
Consult the test cases for usage examples.