hash
Returns the lowercase hex digest of the value under the named algorithm, one of sha256, sha512, sha1, or md5.
The algorithm is required and there is no default, so a template always names the algorithm it was written against and nothing silently moves under it later. An unrecognized name is an error rather than a fallback to some other algorithm.
The bytes are hashed exactly as they arrive, with no trimming, case folding, or other normalization, so a digest computed here matches one computed elsewhere over the same input.
sha1 and md5 are offered because a template often has to reproduce a digest another system already published, a Gravatar URL or a stored checksum among them. Neither is safe where a reader must not be able to forge the input.
stringstringstringBehaviors
- Coerces scalars to text
- A scalar value such as a number or a boolean is converted to its text form before matching, so
42is accepted as"42".
Digests the value with the named algorithm and returns lowercase hex.
Given
{"token": "hello"}Template
{{ token | hash:'sha256' }}Result
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824Names md5 to reproduce a digest another system published, such as a Gravatar URL.
Given
{"email": "hello"}Template
{{ email | hash:'md5' }}Result
5d41402abc4b2a76b9719d911017c592Takes a number value as its string form, so the digest is the one of "42".
Given
{"id": 42}Template
{{ id | hash:'sha256' }}Result
73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049