测试用户
2023-04-13 43393f2bb11cbf9e6af40077bbc5284660e8a754
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.common.configure;
 
import com.common.core.utils.SM4Utils;
import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyResolver;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * @author 廖振钦
 * @date 21/12/2021 15:36
 * @desc 自动解密
 */
@Configuration
public class EncryptionPropertyConfig {
 
    @Bean(name = "encryptablePropertyResolver")
    public EncryptablePropertyResolver encryptablePropertyResolver() {
        return new EncryptionPropertyResolver();
    }
 
    class EncryptionPropertyResolver implements EncryptablePropertyResolver {
 
        public String resolvePropertyValue(String value) {
            if (StringUtils.isBlank(value)) {
                return value;
            }
            if (value.startsWith("DES@")) {
                return resolveDESValue(value.substring(4));
            }
            return value;
        }
 
        private String resolveDESValue(String value) {
 
            return SM4Utils.decryptStr(value);
        }
 
    }
}