Skip to main content
sha256(str) returns the lowercase hexadecimal SHA-256 hash of str.

Signature

Example

Compute a cache key based on a lock file’s contents so that the cache is invalidated when dependencies change:
The cache key changes whenever go.sum changes, which means the module cache is only reused when the exact same dependencies are declared.

Notes

  • The output is always a 64-character lowercase hexadecimal string.
  • sha256 hashes the string value passed to it. To hash a text file, pass it through file. For binary files, use a shell command like sha256sum instead.
  • For non-security use cases like cache keys, md5 is faster and produces a shorter hash.