{"record":{"id":"1e4ca22677e26f8a","repo":"gohugoio/hugo","slug":"crypto-hash-q-is-not-a-supported-hash-algorithm","errorCode":null,"errorMessage":"crypto.Hash: %q is not a supported hash algorithm","messagePattern":"crypto\\.Hash: %q is not a supported hash algorithm","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/crypto/crypto.go","lineNumber":123,"sourceCode":"\t}\n\n\treturn hex.EncodeToString(h.Sum(nil)), nil\n}\n\nfunc newHash(algo string) (hash.Hash, error) {\n\tswitch algo {\n\tcase \"md5\":\n\t\treturn md5.New(), nil\n\tcase \"sha1\":\n\t\treturn sha1.New(), nil\n\tcase \"sha256\":\n\t\treturn sha256.New(), nil\n\tcase \"sha384\":\n\t\treturn sha512.New384(), nil\n\tcase \"sha512\":\n\t\treturn sha512.New(), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"crypto.Hash: %q is not a supported hash algorithm\", algo)\n\t}\n}\n\n// HMAC returns a cryptographic hash that uses a key to sign a message.\nfunc (ns *Namespace) HMAC(h any, k any, m any, e ...any) (string, error) {\n\tha, err := cast.ToStringE(h)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tvar hash func() hash.Hash\n\tswitch ha {\n\tcase \"md5\":\n\t\thash = md5.New\n\tcase \"sha1\":\n\t\thash = sha1.New\n\tcase \"sha256\":\n\t\thash = sha256.New","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/crypto/crypto.go#L105-L141","documentation":"Inside `newHash` (crypto.go:110-124), the algorithm string is matched against `md5`, `sha1`, `sha256`, `sha384`, `sha512`. Any other value reaches the `default` arm and returns this error quoting the unsupported algorithm. Note `sha384` is supported here but not in `crypto.HMAC`.","triggerScenarios":"`{{ crypto.Hash \"sha3\" $value }}`, `{{ crypto.Hash \"SHA256\" $value }}` (uppercase — matching is case-sensitive), or a typo like `sha-256`.","commonSituations":"Using uppercase algorithm names; requesting sha3/blake2 which Hugo does not bundle; copy-pasting an algorithm identifier from another tool's format.","solutions":["Use one of: md5, sha1, sha256, sha384, sha512 (lowercase).","Drop the `crypto.Hash` algo arg entirely to use the sha256 default.","For unsupported algorithms, compute the hash in Go/JS and pass the result to the template."],"exampleFix":"// before\n{{ crypto.Hash \"SHA-256\" $value }}\n// after\n{{ crypto.Hash \"sha256\" $value }}","handlingStrategy":"validation","validationCode":"{{/* Valid algos: md5, sha1, sha256, sha384, sha512 (lowercase) */}}\n{{ crypto.Hash \"sha256\" $value }}\n{{ crypto.Hash $value }} {{/* defaults to sha256 */}}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use lowercase algorithm names exactly as documented.","Remember sha384 is valid for Hash but not HMAC.","For sha3/blake2, compute in Go and pass the hex result."],"tags":["hugo","go-templates","crypto","hash","invalid-argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}