
使用pringboot对数据库地址进行加密的方法
1.首先,需要在springboot项目中导入依赖;
com.github.ulisesbocchio
jasypt-spring-boot-starter
2.0.0
2.依赖导入好后,在springboot中输入代码即可对数据库地址进行加密;
public class EncryptionPropertyConfig {
@Bean(name="encryptablePropertyResolver")
public EncryptablePropertyResolver encryptablePropertyResolver() {
return new EncryptionPropertyResolver();
}
class EncryptionPropertyResolver implements EncryptablePropertyResolver {
@Override
public String resolvePropertyValue(String value) {
if(StringUtils.isBlank(value)) {
return value;
}
// 值以DES@开头的均为DES加密,需要解密
if(value.startsWith("xxxxx@")) {
return resolveDESValue(value.substring(11));
}
// 不需要解密的值直接返回
return value;
}
private String resolveDESValue(String value) {
// 自定义DES密文解密
String decode="";
try{
decode = DESCode.decode(value);
}catch (Exception e){
e.printStackTrace();
System.out.println("解密失败!:"+ value);
}
System.out.println("value :"+value +" :"+decode);
return decode;
}
}
}
以上就是关于“springboot如何给数据库地址加密”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm