springboot如何给数据库地址加密

1230
2021/1/18 11:01:55
栏目: 网络安全
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

springboot如何给数据库地址加密

使用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;

}

}

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: springboot调用外部接口失败怎么处理