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