rain
2024-06-13 cbb68695817f3008c9d965487322c21ec822a42d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.dji.sample.territory.utils;
 
import com.dji.sample.territory.utils.jym.SM2SignVO;
import com.dji.sample.territory.utils.jym.SM2SignVerUtils;
import com.dji.sample.territory.utils.jym.Util;
import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;
 
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
 
public class SM3 {
    public static String sm3(byte[] data) {
        byte[] md = new byte[32];
        SM3Digest sm3 = new SM3Digest();
        sm3.update(data, 0, data.length);
        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,"中图智绘无人机",
                "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D");
        System.out.println(addJym(buffer));
    }
 
    public static String addJym(StringBuffer buffer) throws Exception {
        String hash = SM3.sm3(buffer.toString().getBytes());
        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) {
        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;
    }
}