zoukankan      html  css  js  c++  java
  • springboot +jasypt 配置文件加密

    		<dependency>
    			<groupId>com.github.ulisesbocchio</groupId>
    			<artifactId>jasypt-spring-boot-starter</artifactId>
    			<version>3.0.3</version>
    		</dependency>
    
    spring.datasource.dbtype=mysql
    #mysql
    spring.datasource.url = jdbc:mysql://10.20.90.71:3306/netauth?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=GMT%2B8
    spring.datasource.username = root
    spring.datasource.password = ENC(/auAXILSXrWcWzNOYMql/g==)
    spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
    spring.datasource.max-idle = 20
    spring.datasource.max-wait = 1000
    spring.datasource.min-idle = 2
    spring.datasource.initial-size = 5
    #获取连接最多等待时间
    spring.datasource.idle-timeout = 150
    #创建连接时是否测试
    spring.datasource.test-on-connect = false
    ## 实现jasypt加密解密的类
    jasypt.encryptor.bean = desencrypt
    
    package com.infosec.config;
    
    import org.apache.commons.lang.StringUtils;
    import org.jasypt.encryption.StringEncryptor;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Component;
    
    import com.netauth.utils.NetSignUtils;
    
    @Component("desencrypt")
    public class NrStringEncryptor implements StringEncryptor {
        private static Logger logger = LoggerFactory.getLogger(NrStringEncryptor.class);
    
        @Override
        public String encrypt(String message) {
            if (StringUtils.isNotBlank(message)){
                try {
                    logger.info("加密前密码:"+message);
                   // message = encryptDecryptService.encrypt(message);
                    logger.info("加密后密码:"+message);
                    logger.info("配置信息加密成功!");
                } catch (Exception e) {
                    logger.error("配置信息加密失败!");
                }
            }
            return message;
        }
    
        @Override
        public String decrypt(String encryptedMessage) {
            if (StringUtils.isNotBlank(encryptedMessage)){
                try {
                    encryptedMessage = NetSignUtils.getSymmDecrypt(encryptedMessage);
                    logger.info("配置信息解密成功!");
                } catch (Exception e) {
                    logger.error("配置信息解密失败!");
                }
            }
            return encryptedMessage;
        }
    }
    
  • 相关阅读:
    16个激发你创新灵感的网站设计资源
    时髦而精巧的Iphone墙纸收集
    分享一个比lightbox配置更方便的jQuery web2.0图片显示插件:Topup
    使用HTML5,CSS3和jQuery来增强网站的用户体验和使用乐趣5
    使用Beautify.js来美化你的jQuery代码
    分享10个jQuery的全景图片展示插件
    使用sublime text 2开发Javacript和jQuery
    分享10个便利的HTML5/CSS3框架
    分享5个javascript的数字格式化函数
    分享10个必备的简化Web设计的HTML5工具
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/15220892.html
Copyright © 2011-2022 走看看