{"id":"4702c18d2c77f9fc","repo":"gohugoio/hugo","slug":"q-is-not-a-supported-encoding-method","errorCode":null,"errorMessage":"%q is not a supported encoding method","messagePattern":"%q is not a supported encoding method","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/crypto/crypto.go","lineNumber":178,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tencoding := \"hex\"\n\tif len(e) > 0 && e[0] != nil {\n\t\tencoding, err = cast.ToStringE(e[0])\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tswitch encoding {\n\tcase \"binary\":\n\t\treturn string(mac.Sum(nil)[:]), nil\n\tcase \"hex\":\n\t\treturn hex.EncodeToString(mac.Sum(nil)[:]), nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"%q is not a supported encoding method\", encoding)\n\t}\n}\n","sourceCodeStart":160,"sourceCodeEnd":181,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/crypto/crypto.go#L160-L181","documentation":"`hmac` takes an optional fourth argument selecting the output encoding of the MAC. Only `\"hex\"` (the default) and `\"binary\"` are accepted; any other value — including common expectations like `\"base64\"` — hits the switch default and returns this error after the MAC has been computed.","triggerScenarios":"`{{ hmac \"sha256\" $key $msg \"base64\" }}`; `{{ hmac \"sha256\" $key $msg \"Hex\" }}` (case-sensitive); passing a non-encoding value as the fourth argument by mistake.","commonSituations":"Provider docs (Slack, AWS, payment gateways) that specify base64-encoded signatures — developers pass \"base64\" expecting it to work; extra trailing arguments left over from refactoring; templating the encoding from config with a typo.","solutions":["Use \"hex\" or \"binary\" — those are the only supported encodings; \"hex\" is the default, so you can usually omit the argument.","For a base64 signature, request binary output and encode it: `{{ hmac \"sha256\" $key $msg \"binary\" | base64Encode }}`.","Remove the fourth argument entirely if hex output is acceptable."],"exampleFix":"<!-- before -->\n{{ hmac \"sha256\" $key $msg \"base64\" }}\n<!-- after -->\n{{ hmac \"sha256\" $key $msg \"binary\" | base64Encode }}","handlingStrategy":"validation","validationCode":"{{ $enc := \"hex\" }}\n{{ if in (slice \"hex\" \"binary\") $enc }}{{ hmac \"sha256\" $secret $msg $enc }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass supported encoding values (e.g. \"hex\", \"binary\") as the optional 4th hmac argument","Omit the encoding argument to get the default hex output","Validate encoding strings from site config before use"],"tags":["hugo","templates","crypto","encoding"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}