Explorar o código

feat(util): 优化HMAC-MD5签名生成工具方法

- 删除AES加密工具类中的KEY_SIZE常量定义
- 更新运营商密钥及新增运营商ID常量配置
- 增加按指定顺序拼接参数生成签名的genSign方法
- 修改HMAC-MD5签名结果转为大写格式输出
wzq hai 4 semanas
pai
achega
46b588752c

+ 6 - 1
src/main/java/com/zsElectric/boot/common/constant/ConnectivityConstants.java

@@ -8,10 +8,15 @@ package com.zsElectric.boot.common.constant;
  */
 public interface ConnectivityConstants {
 
+    /**
+     * 运营商ID
+     */
+    String OPERATOR_ID = "MAA9A6L75";
+
     /**
      * 运营商密钥
      */
-    String OPERATOR_SECRET = "R47nY0QNSlPb3bRKmUjp20VF";
+    String OPERATOR_SECRET = "Sov2Gs590CLUbx4g";
 
     /**
      * 签名密钥

+ 0 - 1
src/main/java/com/zsElectric/boot/common/util/AESCryptoUtil.java

@@ -16,7 +16,6 @@ public class AESCryptoUtil {
     // 加密算法/模式/填充方式
     private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
     private static final String AES = "AES";
-    private static final int KEY_SIZE = 128; // 128位
     private static final int IV_SIZE = 16;   // 16字节
     
     /**

+ 23 - 1
src/main/java/com/zsElectric/boot/common/util/HmacMD5Util.java

@@ -14,6 +14,28 @@ public class HmacMD5Util {
     private static final int BLOCK_SIZE = 64; // 块大小为64字节
     private static final byte IPAD = 0x36;   // 内部填充常量
     private static final byte OPAD = 0x5C;   // 外部填充常量
+
+
+    /**
+     * 根据入参顺序生成签名: OperatorID+Data+TimeStamp+Seq
+     * @param operatorId 操作员ID
+     * @param data 数据内容
+     * @param timeStamp 时间戳
+     * @param seq 序列号
+     * @param sigSecret 签名密钥
+     * @return 签名结果(大写)
+     * @throws NoSuchAlgorithmException
+     */
+    public static String genSign(
+            String operatorId,
+            String data,
+            String timeStamp,
+            String seq,
+            String sigSecret) throws NoSuchAlgorithmException {
+
+        String content = (operatorId + data + timeStamp + seq).toUpperCase();
+        return hmacMD5Hex(content, sigSecret);
+    }
     
     /**
      * HMAC-MD5签名生成
@@ -128,7 +150,7 @@ public class HmacMD5Util {
             }
             hexString.append(hex);
         }
-        return hexString.toString();
+        return hexString.toString().toUpperCase();
     }
     
     /**