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);
|
}
|
|
}
|
}
|