{"record":{"id":"29b7ecf53afcaa90","repo":"dromara/Sa-Token","slug":"digestalgo","errorCode":null,"errorMessage":"不支持的摘要算法：{digestAlgo}，你可以自定义摘要算法函数实现","messagePattern":"不支持的摘要算法：(.+?)，你可以自定义摘要算法函数实现","errorType":"exception","errorClass":"SaTokenException","httpStatus":null,"severity":"error","filePath":"sa-token-plugin/sa-token-sign/src/main/java/cn/dev33/satoken/sign/config/SaSignConfig.java","lineNumber":118,"sourceCode":"        }\n        // sha1\n        if(digestAlgo.equalsIgnoreCase(\"sha1\")) {\n            return SaSecureUtil.sha1(fullStr);\n        }\n        // sha256\n        if(digestAlgo.equalsIgnoreCase(\"sha256\")) {\n            return SaSecureUtil.sha256(fullStr);\n        }\n        // sha384\n        if(digestAlgo.equalsIgnoreCase(\"sha384\")) {\n            return SaSecureUtil.sha384(fullStr);\n        }\n        // sha512\n        if(digestAlgo.equalsIgnoreCase(\"sha512\")) {\n            return SaSecureUtil.sha512(fullStr);\n        }\n        // 未知\n        throw new SaTokenException(\"不支持的摘要算法：\" + digestAlgo + \"，你可以自定义摘要算法函数实现\");\n    };\n\n    /**\n     * 设置: 对 fullStr 的摘要算法函数\n     *\n     * @param digestMethod /\n     * @return 对象自身\n     */\n    public SaSignConfig setDigestMethod(SaParamRetFunction<String, String> digestMethod) {\n        this.digestMethod = digestMethod;\n        return this;\n    }\n\n\n\n    // -------------- get/set\n\n    /**","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-plugin/sa-token-sign/src/main/java/cn/dev33/satoken/sign/config/SaSignConfig.java#L100-L136","documentation":"Thrown by SaSignConfig's default digestMethod lambda when the configured digestAlgo is not one of md5, sha1, sha256, sha384, sha512 (case-insensitive) — SaTokenException '不支持的摘要算法'. The API-signature module uses this algorithm to hash the spliced parameter string; the default implementation only whitelists those five names.","triggerScenarios":"Setting sa-token.sign.digest-algo to something like \"sm3\", \"hmac-sha256\", or a typo (\"sha-256\") and then performing a signature check that invokes digestMethod.","commonSituations":"Compliance requirements demand SM3/HMAC digests; developers assume hyphenated or HMAC names work; upgrading projects copy-paste algorithm names from other libraries.","solutions":["Use one of the supported exact names: md5, sha1, sha256, sha384, sha512 (no hyphens)","For other algorithms, supply your own digest function via setDigestMethod((fullStr) -> MyDigest.hash(fullStr)) instead of digestAlgo"],"exampleFix":"// before\nsignConfig.setDigestAlgo(\"sm3\");\n// after\nsignConfig.setDigestMethod(fullStr -> SmUtil.sm3(fullStr));","handlingStrategy":"validation","validationCode":"java.util.Set<String> supported = java.util.Set.of(\"md5\",\"sha1\",\"sha256\",\"sha384\",\"sha512\");\nif (!supported.contains(digestAlgo.toLowerCase())) throw new IllegalArgumentException(\"use setDigestMethod for custom algorithms\");","typeGuard":null,"tryCatchPattern":"try { config.getDigestMethod().run(fullStr); } catch (SaTokenException e) { failFast(\"unsupported digest algo — switch to setDigestMethod\"); }","preventionTips":["Validate digestAlgo in a startup assertion so misconfig fails at boot","For HMAC/SM3, always go through setDigestMethod, never digestAlgo"],"tags":["api-sign","digest","configuration","crypto"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}