wordpress迁移后地址没变南京网站优化推广
wordpress迁移后地址没变,南京网站优化推广,中国石油销售公司网站建设,贵州网站建设公司推荐SpringBoot整合jasypt加密配置文件敏感信息
在项目中我们需要对配置文件的一些敏感信息进行加密处理#xff0c;比如数据库账户密码#xff0c;避免直接暴露出来#xff0c;这种场景常常用于生产环境#xff0c;我们不想让开发人员知道生产库的密码#xff0c;有运维人员…
SpringBoot整合jasypt加密配置文件敏感信息
在项目中我们需要对配置文件的一些敏感信息进行加密处理比如数据库账户密码避免直接暴露出来这种场景常常用于生产环境我们不想让开发人员知道生产库的密码有运维人员统一管理。
引入依赖
dependencygroupIdcom.github.ulisesbocchio/groupIdartifactIdjasypt-spring-boot-starter/artifactIdversion3.0.4/version/dependency加密工具类
public class JasyptUtils {public static void main(String[] args) {//这里假设我们的数据库密码是rootString info encrypt(root);//加密 TCFVL/wsN9AxelTDQyP/3gSystem.out.println(info);//解密 rootSystem.out.println(decrypt(info));}/*** 加密** param plaintext 明文* return*/public static String encrypt(String plaintext) {StandardPBEStringEncryptor encryptor new StandardPBEStringEncryptor();EnvironmentStringPBEConfig config new EnvironmentStringPBEConfig();// 指定算法config.setAlgorithm(PBEWithMD5AndDES);// 指定秘钥和yml配置文件中保持一致config.setPassword(llp);encryptor.setConfig(config);// 生成加密数据return encryptor.encrypt(plaintext);}/*** 解密** param data 加密后数据* return*/public static String decrypt(String data) {StandardPBEStringEncryptor encryptor new StandardPBEStringEncryptor();EnvironmentStringPBEConfig config new EnvironmentStringPBEConfig();config.setAlgorithm(PBEWithMD5AndDES);config.setPassword(llp);encryptor.setConfig(config);// 解密数据return encryptor.decrypt(data);}
}启动类
SpringBootApplication
MapperScan(basePackages com.llp.jasypt.mapper)
public class JasyptApplication {public static void main(String[] args) {SpringApplication.run(JasyptApplication.class, args);}
}application.yml配置文件
这里我们可以对需要加密的字段进行加密处理比如url、username、password 或者说redis的一些账户信息等等。
jasypt:encryptor:# 加密的秘钥
# password: llp# 加密算法algorithm: PBEWithMD5AndDESiv-generator-classname: org.jasypt.iv.NoIvGeneratorproperty:# 算法识别的前后缀默认ENC()数据库密文示例password: ENC(DzANBAhBWXxZqAOsagIBCoaw8FV4gYRbid7G70UEM24)prefix: Enc(suffix: )spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/llp?autoReconnecttrueuseUnicodetrueuseSSLfalseserverTimezoneGMT%2B8allowMultiQueriestrueusername: Enc(TCFVL/wsN9AxelTDQyP/3g)password: Enc(TCFVL/wsN9AxelTDQyP/3g)#mybatis配置
mybatis:#指定要扫描的mapper.xml位置; classpath:mapper/*.xml 扫描在类路径下的mapper目录下的。xml文件mapper-locations: classpath:mapper/*.xml#配置类型别名,通常指定实体类所在包这样我们在xml中resultTypecom.llp.springboot.mybatis.bean.Monster就可以简写成Monstertype-aliases-package: com.llp.springboot.jasypt.entity#配置mybatis sql打印日志configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl#启用自动驼峰配置map-underscore-to-camel-case: true#通过config-location可以指定mybatis-config.xml这样就可以用传统的方式来配置mybatis#config-location: classpath:mybatis-config.xml启动配置
通常我们不会将password写在配置文件中而是由运维人员进行统一管理,这样开发人员只能看到密文而不知道解密的秘钥
jasypt:encryptor:# 加密的秘钥
# password: llp# 加密算法algorithm: PBEWithMD5AndDESiv-generator-classname: org.jasypt.iv.NoIvGeneratorproperty:# 算法识别的前后缀默认ENC()数据库密文示例password: ENC(DzANBAhBWXxZqAOsagIBCoaw8FV4gYRbid7G70UEM24)prefix: Enc(suffix: )如果打包后部署项目可以使用如下命令在启动项目时指定秘钥
#方式1
java -jar xxx.jar -Djasypt.encryptor.password加密数据的秘钥#方式2
java -jar xxx.jar --jasypt.encryptor.password加密数据的秘钥idea中如何配置启动参数
-Djasypt.encryptor.passwordllp
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/87352.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!