dromara/Sa-Token · error · SaTokenException

不支持的摘要算法:{digestAlgo},你可以自定义摘要算法函数实现

Error message

不支持的摘要算法:{digestAlgo},你可以自定义摘要算法函数实现

What it means

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.

Source

Thrown at sa-token-plugin/sa-token-sign/src/main/java/cn/dev33/satoken/sign/config/SaSignConfig.java:118

        }
        // sha1
        if(digestAlgo.equalsIgnoreCase("sha1")) {
            return SaSecureUtil.sha1(fullStr);
        }
        // sha256
        if(digestAlgo.equalsIgnoreCase("sha256")) {
            return SaSecureUtil.sha256(fullStr);
        }
        // sha384
        if(digestAlgo.equalsIgnoreCase("sha384")) {
            return SaSecureUtil.sha384(fullStr);
        }
        // sha512
        if(digestAlgo.equalsIgnoreCase("sha512")) {
            return SaSecureUtil.sha512(fullStr);
        }
        // 未知
        throw new SaTokenException("不支持的摘要算法:" + digestAlgo + ",你可以自定义摘要算法函数实现");
    };

    /**
     * 设置: 对 fullStr 的摘要算法函数
     *
     * @param digestMethod /
     * @return 对象自身
     */
    public SaSignConfig setDigestMethod(SaParamRetFunction<String, String> digestMethod) {
        this.digestMethod = digestMethod;
        return this;
    }



    // -------------- get/set

    /**

View on GitHub (pinned to ac2c7f6e94)

Solutions

  1. Use one of the supported exact names: md5, sha1, sha256, sha384, sha512 (no hyphens)
  2. For other algorithms, supply your own digest function via setDigestMethod((fullStr) -> MyDigest.hash(fullStr)) instead of digestAlgo

Example fix

// before
signConfig.setDigestAlgo("sm3");
// after
signConfig.setDigestMethod(fullStr -> SmUtil.sm3(fullStr));
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> supported = java.util.Set.of("md5","sha1","sha256","sha384","sha512");
if (!supported.contains(digestAlgo.toLowerCase())) throw new IllegalArgumentException("use setDigestMethod for custom algorithms");

Try / catch

try { config.getDigestMethod().run(fullStr); } catch (SaTokenException e) { failFast("unsupported digest algo — switch to setDigestMethod"); }

Prevention

When it happens

Trigger: 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.

Common situations: Compliance requirements demand SM3/HMAC digests; developers assume hyphenated or HMAC names work; upgrading projects copy-paste algorithm names from other libraries.

Related errors


AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14). Data as JSON: /api/errors/29b7ecf53afcaa90. Report an issue: GitHub.