gohugoio/hugo · error
is not a supported encoding method
Error message
%q is not a supported encoding method
What it means
`crypto.HMAC` accepts an optional fourth argument selecting output encoding (crypto.go:164-179). After defaulting to `hex`, it matches only `binary` or `hex`; any other value reaches the `default` arm and returns this error quoting the unsupported encoding.
Solutions
- Use `hex` (default) or `binary` as the encoding argument.
- For base64, take the hex output and apply `encoding.Base64Encode` on the decoded bytes, or compute in Go.
- Omit the encoding argument to get hex.
Example fix
// before
{{ crypto.HMAC "sha256" $key $msg "base64" }}
// after
{{ crypto.HMAC "sha256" $key $msg "hex" }}
{{ crypto.HMAC "sha256" $key $msg }} Defensive patterns
Strategy: validation
Validate before calling
{{/* Valid encodings: hex (default), binary */}}
{{ crypto.HMAC "sha256" $key $msg }}
{{ crypto.HMAC "sha256" $key $msg "binary" }} Prevention
- Use only `hex` or `binary` for the encoding argument.
- Omit the arg entirely for hex output.
- Post-process hex output for base64 in a separate step if needed.
When it happens
Trigger: `{{ crypto.HMAC "sha256" $key $msg "base64" }}` (base64 not supported), `{{ crypto.HMAC ... "HEX" }}` (uppercase), or a typo.
Common situations: Expecting base64 output (common for tokens/signatures); passing uppercase; copy-pasting an encoding name from a different library.
Related errors
- hmac: is not a supported hash function
- crypto.Hash: is not a supported hash algorithm
- crypto.Hash: expected 1 or 2 arguments, got
- unsupported transpiler
- can't evaluate a nil pointer of type
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/4702c18d2c77f9fc.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/crypto/crypto.go:178
if err != nil {
return "", err
}
encoding := "hex"
if len(e) > 0 && e[0] != nil {
encoding, err = cast.ToStringE(e[0])
if err != nil {
return "", err
}
}
switch encoding {
case "binary":
return string(mac.Sum(nil)[:]), nil
case "hex":
return hex.EncodeToString(mac.Sum(nil)[:]), nil
default:
return "", fmt.Errorf("%q is not a supported encoding method", encoding)
}
}
View on GitHub (pinned to 52c9bd7908)