sha1

Generates a SHA1 hash of a string. Returns a hex-encoded hash string.

{% assign hash = "hello world" | sha1 %}
{% log hash %}

Output:

2aae6c35c94fcfb415dbe95f408b9ce91ee846ed

Syntax

{{ value | sha1 }}
Parameter
Description

value

The string to hash

Return Value

Returns a hex-encoded SHA1 hash string (40 characters).

Examples

Generate a hash for deduplication:

{% assign content_hash = email.body.text | sha1 %}
{% log "Content hash: " | append: content_hash %}

Create a cache key:

{% capture cache_key_input %}{{ product.id }}-{{ product.updated_at }}{% endcapture %}
{% assign cache_key = cache_key_input | sha1 %}
{% log cache_key %}

Generate a unique identifier from combined fields:

Notes

  • Always returns a hex-encoded string (lowercase, 40 characters)

  • SHA1 is suitable for checksums and deduplication, but not for security-sensitive operations

  • For HMAC-based authentication, use hmac_sha256 instead

  • See also: hmac_sha256, base64_encode

Last updated