彭雪彬
2025-09-05 1b1215fbeb15f860e134a0ae32bbe0fb11926446
oying-system/src/main/java/com/oying/modules/hwc/utils/SignUtil.java
@@ -40,7 +40,8 @@
    /**
     * 对返回参数的验证签名
     */
    public static boolean verifySign(String sign, String signType, Map<String, String> resultMap, SwiftPassProperties properties, PayTypeEnum status) throws Exception {
    public static boolean verifySign(String sign, String signType, Map<String, String> resultMap,
                                     SwiftPassProperties properties, PayTypeEnum status)  {
        if ("RSA_1_256".equals(signType)) {
            Map<String, String> params = SignUtils.paraFilter(resultMap);
            StringBuilder builder = new StringBuilder((params.size() + 1) * 10);
@@ -62,7 +63,7 @@
    /**
     * RSA_1_256 验证签名
     */
    public static boolean verifySign(String preStr, String sign, String signType, String platPublicKey) throws Exception {
    public static boolean verifySign(String preStr, String sign, String signType, String platPublicKey) {
        // 调用这个函数前需要先判断是MD5还是RSA
        // 商户的验签函数要同时支持MD5和RSA
        RSAUtil.SignatureSuite suite;
@@ -71,7 +72,7 @@
        } else if ("RSA_1_256".equals(signType)) {
            suite = RSAUtil.SignatureSuite.SHA256;
        } else {
            throw new Exception("不支持的签名方式");
            throw new BadRequestException("不支持的签名方式");
        }
        return RSAUtil.verifySign(suite, preStr.getBytes(StandardCharsets.UTF_8), Base64.decodeBase64(sign.getBytes(StandardCharsets.UTF_8)),
                platPublicKey);
@@ -80,14 +81,14 @@
    /**
     * RSA_1_256生成不同的sign
     */
    public static String sign(String preStr, String signType, String mchPrivateKey) throws Exception {
    public static String sign(String preStr, String signType, String mchPrivateKey) {
        RSAUtil.SignatureSuite suite;
        if ("RSA_1_1".equals(signType)) {
            suite = RSAUtil.SignatureSuite.SHA1;
        } else if ("RSA_1_256".equals(signType)) {
            suite = RSAUtil.SignatureSuite.SHA256;
        } else {
            throw new Exception("不支持的签名方式");
            throw new BadRequestException("不支持的签名方式");
        }
        byte[] signBuf = RSAUtil.sign(suite, preStr.getBytes(StandardCharsets.UTF_8),
                mchPrivateKey);