2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
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
59
60
61
62
63
64
65
66
67
68
69
70
package cn.iocoder.yudao.framework.encrypt.config;
 
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
 
/**
 * HTTP API 加解密配置
 *
 * @author 芋道源码
 */
@ConfigurationProperties(prefix = "yudao.api-encrypt")
@Validated
@Data
public class ApiEncryptProperties {
 
    /**
     * 是否开启
     */
    @NotNull(message = "是否开启不能为空")
    private Boolean enable;
 
    /**
     * 请求头(响应头)名称
     *
     * 1. 如果该请求头非空,则表示请求参数已被「前端」加密,「后端」需要解密
     * 2. 如果该响应头非空,则表示响应结果已被「后端」加密,「前端」需要解密
     */
    @NotEmpty(message = "请求头(响应头)名称不能为空")
    private String header = "X-Api-Encrypt";
 
    /**
     * 对称加密算法,用于请求/响应的加解密
     *
     * 目前支持
     * 【对称加密】:
     *      1. {@link cn.hutool.crypto.symmetric.SymmetricAlgorithm#AES}
     *      2. {@link cn.hutool.crypto.symmetric.SM4#ALGORITHM_NAME} (需要自己二次开发,成本低)
     * 【非对称加密】
     *      1. {@link cn.hutool.crypto.asymmetric.AsymmetricAlgorithm#RSA}
     *      2. {@link cn.hutool.crypto.asymmetric.SM2} (需要自己二次开发,成本低)
     *
     * @see <a href="https://help.aliyun.com/zh/ssl-certificate/what-are-a-public-key-and-a-private-key">什么是公钥和私钥?</a>
     */
    @NotEmpty(message = "对称加密算法不能为空")
    private String algorithm;
 
    /**
     * 请求的解密密钥
     *
     * 注意:
     * 1. 如果是【对称加密】时,它「后端」对应的是“密钥”。对应的,「前端」也对应的也是“密钥”。
     * 2. 如果是【非对称加密】时,它「后端」对应的是“私钥”。对应的,「前端」对应的是“公钥”。(重要!!!)
     */
    @NotEmpty(message = "请求的解密密钥不能为空")
    private String requestKey;
 
    /**
     * 响应的加密密钥
     *
     * 注意:
     * 1. 如果是【对称加密】时,它「后端」对应的是“密钥”。对应的,「前端」也对应的也是“密钥”。
     * 2. 如果是【非对称加密】时,它「后端」对应的是“公钥”。对应的,「前端」对应的是“私钥”。(重要!!!)
     */
    @NotEmpty(message = "响应的加密密钥不能为空")
    private String responseKey;
 
}