• ADADADADAD

    springboot如何给数据库地址加密[ 网络知识 ]

    网络知识 时间:2024-12-03 15:09:53

    作者:文/会员上传

    简介:

    使用pringboot对数据库地址进行加密的方法1.首先,需要在springboot项目中导入依赖;com.github.ulisesbocchiojasypt-spring-boot-starter2.0.02.依赖导入好后,在springboot中输

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    使用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如何给数据库地址加密.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载