教育训练处考试制证系统后端
heheng
2025-02-21 5b8607464905c4a585fb8e859985730e1ee61f40
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
package com.gkhy.exam.pay.utils;
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Date;
 
public class SignCommond {
 
    public SignDto signSm3Detach(String plain) {
 
        try {
            // 使用 SM3 算法生成摘要
            MessageDigest md = MessageDigest.getInstance("SM3");
            byte[] hashBytes = md.digest(plain.getBytes());
 
            // 将摘要转换为 Base64 编码的字符串
            String signatureValue = Base64.getEncoder().encodeToString(hashBytes);
 
            SignDto signDto = new SignDto(new Date(), signatureValue, "1234567890", "issuerDn");
 
            return signDto;
 
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
 
        return null;
    }
}