From 4b067b4db5c1f2a068d6e27cc138118810785e2d Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 07 五月 2025 10:47:13 +0800
Subject: [PATCH] 1、创建命令生成器模块,实现部分命令数据生成,还需继续实现其他命令; 2、完善代码。
---
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java
new file mode 100644
index 0000000..176dd63
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java
@@ -0,0 +1,43 @@
+package com.dy.pipIrrSell.util;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-03-06 11:47
+ * @LastEditTime 2024-03-06 11:47
+ * @Description
+ */
+public class HmacSha256 {
+ public static String getSignature(String secretKey, String data) throws NoSuchAlgorithmException, InvalidKeyException {
+ // 鍒涘缓瀵嗛挜瀵硅薄
+ byte[] keyBytes = secretKey.getBytes(StandardCharsets.UTF_8);
+ SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "HmacSHA256");
+
+ // 鍒涘缓Mac瀵硅薄骞跺垵濮嬪寲
+ Mac mac = Mac.getInstance("HmacSHA256");
+ mac.init(secretKeySpec);
+
+ // 灏嗗緟鍔犲瘑鐨勬暟鎹浆鎹负瀛楄妭鏁扮粍
+ byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
+
+ // 浣跨敤瀵嗛挜瀵规暟鎹繘琛屽姞瀵�
+ byte[] encryptedBytes = mac.doFinal(dataBytes);
+
+ // 灏嗗姞瀵嗗悗鐨勭粨鏋滆浆鎹负鍗佸叚杩涘埗瀛楃涓�
+ StringBuilder hexString = new StringBuilder();
+ for (byte b : encryptedBytes) {
+ String hex = Integer.toHexString(0xff & b);
+ if (hex.length() == 1) {
+ hexString.append('0');
+ }
+ hexString.append(hex);
+ }
+ String hmacSha256 = hexString.toString();
+ return hmacSha256;
+ }
+}
\ No newline at end of file
--
Gitblit v1.8.0