From 5655be710d599928a1d03db792212da5bf1ce667 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 14 Jun 2024 09:58:09 +0800
Subject: [PATCH] db校验

---
 src/main/java/com/dji/sample/territory/utils/SM3.java |   64 +++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/dji/sample/territory/utils/SM3.java b/src/main/java/com/dji/sample/territory/utils/SM3.java
index 1156dbb..d96d394 100644
--- a/src/main/java/com/dji/sample/territory/utils/SM3.java
+++ b/src/main/java/com/dji/sample/territory/utils/SM3.java
@@ -23,37 +23,67 @@
         return s.toUpperCase();
     }
 
+    public static String sm3(String input) {
+        // 将输入的字符串转换为字节数组
+        byte[] data = input.getBytes();
+
+        // 创建一个字节数组,用于存储加密结果
+        byte[] md = new byte[32];
+
+        // 创建SM3加密对象
+        SM3Digest sm3 = new SM3Digest();
+
+        // 更新加密对象,传入数据
+        sm3.update(data, 0, data.length);
+
+        // 完成加密,并将结果存储到md数组
+        sm3.doFinal(md, 0);
+
+        // 将字节数组转换为十六进制字符串
+        String s = new String(Hex.encode(md));
+
+        // 返回大写的十六进制字符串
+        return s.toUpperCase();
+    }
+
+
+
 
     public static void main(String[] args) throws Exception {
-        File file = new File("src/main/resources/FJ_11.jpeg");
-        byte[] bytesArray = Files.readAllBytes(file.toPath());
-        String sm=sm3(bytesArray);
-        StringBuffer buffer=addStringBuffer("0561C8D116010B96128A7470436CDEF2DA1F2BCBD21CA228E427D27AFDA5BF10",
-                "2024-06-11 09:29:44",115.8652884,28.6252874,-83,295,0,"中图智绘无人机",
+//        File file = new File("src/main/resources/FJ_11.jpeg");
+//        byte[] bytesArray = Files.readAllBytes(file.toPath());
+//        String sm = sm3(bytesArray);
+//        System.out.println(sm);
+        StringBuffer buffer = addStringBuffer("0561C8D116010B96128A7470436CDEF2DA1F2BCBD21CA228E427D27AFDA5BF10",
+                "2024-06-11 09:29:44", 115.8652884, 28.6252874, -83, 295, 0, "中图智绘无人机",
                 "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D");
         System.out.println(addJym(buffer));
+        String hash = SM3.sm3(buffer.toString().getBytes());
+        System.out.println(hash);
+        String input="0561C8D116010B96128A7470436CDEF2DA1F2BCBD21CA228E427D27AFDA5BF10,2024-06-11 09:29:44, 115.8652884, 28.6252874, -83, 295, 0, 中图智绘无人机,23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D";
+        System.out.println(sm3(input));
     }
 
     public static String addJym(StringBuffer buffer) throws Exception {
-        String hash = SM3.sm3(buffer.toString().getBytes());
+        String hash = SM3.sm3(buffer.toString());
         String privateKey = "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D";
         SM2SignVO sm2signv0 = SM2SignVerUtils.Sign2SM2(Util.hexStringToBytes(privateKey), hash.getBytes(StandardCharsets.UTF_8));
         return sm2signv0.getSm2_signForHard().toUpperCase();
     }
 
-    public static StringBuffer addStringBuffer(String FJHXZ, String PSSJ, Double Longitude, Double Latitude, double PSFYJ, double PSJD, int PSHGJ, String PSRY, String ZSDM) {
+    public static StringBuffer addStringBuffer(String FJHXZ, String PSSJ, Double Longitude, Double Latitude, int PSFYJ, int PSJD, int PSHGJ, String PSRY, String ZSDM) {
         StringBuffer buffer = new StringBuffer();
         // 添加参数到 StringBuffer
-          buffer.append(FJHXZ).append(",")
-                .append(PSSJ).append(",")
-                .append(Longitude).append(",")
-                .append(Latitude).append(",")
-                .append(PSFYJ).append(",")
-                .append(PSJD).append(",")
-                .append(PSHGJ).append(",")
-                .append(PSRY).append(",")
-                .append(ZSDM);
-                 return buffer;
+        buffer.append(FJHXZ).append(",");
+        buffer.append(PSSJ).append(",");
+        buffer.append(Longitude).append(",");
+        buffer.append(Latitude).append(",");
+        buffer.append(PSFYJ).append(",");
+        buffer.append(PSJD).append(",");
+        buffer.append(PSHGJ).append(",");
+        buffer.append(PSRY).append(",");
+        buffer.append(ZSDM);
+        return buffer;
     }
 }
 

--
Gitblit v1.9.3