admin
2025-03-29 9cd0e111d7315074f5574558dab3cae087ff1f68
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
package com.billion.main.licenes;
 
import java.security.SecureRandom;
import java.util.Base64;
 
import static cn.hutool.crypto.SecureUtil.sha256;
 
public class SecretKeyGenerator {
 
    /**
     * 生成密钥
     * @param keyLength 密钥长度(字节)
     * @return 生成的密钥
     */
    public static String generateSecretKey(int keyLength) {
        SecureRandom secureRandom = new SecureRandom();
        byte[] key = new byte[keyLength];
        secureRandom.nextBytes(key);
        return Base64.getEncoder().encodeToString(key);
    }
 
    /**
     * 生成授权签名
     * @param content 需要签名的内容
     * @param secretKey 密钥
     * @return 签名结果
     */
    public static String generateSignature(String content, String secretKey) {
        try {
            return sha256(content + secretKey);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
 
    public static void main(String[] args) {
 
    }
}