From c9fe1b65bf3b2cf2a935edeb3370f73a55f0ce67 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期六, 10 五月 2025 08:58:19 +0800
Subject: [PATCH] 修改《打包发布配置修改》文档
---
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java
new file mode 100644
index 0000000..9f5e7c2
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java
@@ -0,0 +1,43 @@
+package com.dy.pipIrrWechat.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-07-15 10:19
+ * @LastEditTime 2024-07-15 10:19
+ * @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