springboot 集成mybatis-plus_Spring Boot

springboot 集成mybatis-plus_Spring Bootspringboot集成jasyptJasypt不简介了,懒得在官网copy,直接传送官网说啥都假的,简单粗暴直接上代码引入依赖<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-start

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

springboot 集成 jasypt

Jasypt不简介了,懒得在官网copy, 直接传送官网

说啥都假的,简单粗暴直接上代码

  1. 引入依赖
<dependency>
	<groupId>com.github.ulisesbocchio</groupId>
	<artifactId>jasypt-spring-boot-starter</artifactId>
	<version>2.1.0</version>
</dependency>
  1. 配置加密参数
    2.1 使用 properties文件配置
    jasypt.encryptor.password=jasypt
    2.2 使用 yml文件配置
jasypt:
  encryptor:
    password: jasypt

除了以上两种配置个人推荐使用启动参数配置
idea 配置方法
在这里插入图片描述

  1. 两种生成加密密匙方式
    3.1 使用spring boot单元测试
    
    import org.jasypt.encryption.StringEncryptor;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class JasyptTest { 
         
    
    	@Autowired
    	private StringEncryptor stringEncryptor;
    
    	@Test
    	public void encryptPwd() { 
         
    		//加密123456
        	String result = stringEncryptor.encrypt("123456");
        	System.out.println(result);
    	}
    
    }
    

    3.2 使用工具类

    import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
    import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
    
    /** * @author shuzhuo * @date 2019/1/9 9:56 */
    public class JasyptUtil { 
         
    
    	/** * Jasypt生成加密结果 * @param password 配置文件中设定的加密密 * @param value 加密值 * @return */
    	public static String encyptPwd(String password,String value){ 
         
        	PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        	encryptor.setConfig(cryptor(password));
        	String result = encryptor.encrypt(value);
        	return result;
    	}
    
    	/** * 解密 * @param password 配置文件中设定的加密密码 * @param value 解密密文 * @return */
    	public static String decyptPwd(String password,String value){ 
         
        	PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        	encryptor.setConfig(cryptor(password));
        	String result = encryptor.decrypt(value);
        	return result;
    	}
    
    	public static SimpleStringPBEConfig cryptor(String password){ 
         
        	SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        	config.setPassword(password);
        	config.setAlgorithm("PBEWithMD5AndDES");
        	config.setKeyObtentionIterations("1000");
        	config.setPoolSize("1");
        	config.setProviderName("SunJCE");
        	config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        	config.setStringOutputType("base64");
        	return config;
    	}
    
    	public static void main(String[] args){ 
         
        	//加密
        	System.out.println(encyptPwd("jasypt","123456"));
        	//解密
        	System.out.println(decyptPwd("jasypt","lnzpDZItgjAntHqsYPFTew=="));
    	}
    }
    
  2. 将生成的加密密匙配置在配置文件中即可,ENC 是约定的关键字,在启动时会解析所有 PropertySource 中的加密属性。
    4.1 这里更改yml配置中连接数据库的密码
spring:
  datasource:
    password: ENC(lnzpDZItgjAntHqsYPFTew==)

如果是使用启动参数配置打包为jar 或war怎么配置呢?

jar: 命令:java -Djasypt.encryptor.password=jasypt -jar xxx.jar

war:
到Tomcat的bin目录下,打开文件catalina.bat/catalina.sh,添加如下参数,然后保存
加上启动参数配置
window:catalina.bat
set JAVA_OPTS="-Djasypt.encryptor.password=jasypt"
在这里插入图片描述

Linux:catalina.sh
JAVA_OPTS="-Djasypt.encryptor.password=jasypt"
在这里插入图片描述

或者直接在tomcat bin 目录新建setenv.bat setenv.sh
文件内容如下
Windows:
set JAVA_OPTS="-Djasypt.encryptor.password=jasypt"
Linux:
export JAVA_OPTS="-Djasypt.encryptor.password=jasypt"

更多请参考 jasypt github 文档

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/189267.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Spring学习—生成图片验证码

    今天想学下一下验证码的生成,就之前搭建好的一个spring框架上写了一个demo,我会贴出细节代码,但是spring的配置就不在介绍了。需要完整代码可以联系我! 会从前台页面到后台实现完整的讲解: 1:前台的代码,image.jsp<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="U

    2022年2月25日
    45
  • eplan激活码破解步骤【2021最新】

    (eplan激活码破解步骤)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年3月26日
    380
  • Python知识点(史上最全)

    Python知识点(史上最全)Python期末考试知识点(史上最全)python简介Python是一种解释型语言Python使用缩进对齐组织代码执行,所以没有缩进的代码,都会在载入时自动执行数据类型:整形int无限大浮点型float小数复数complex由实数和虚数组成Python中有6个标准的数据类型:

    2022年5月14日
    43
  • 查看Linux内核版本及发行版本「建议收藏」

    查看Linux内核版本及发行版本「建议收藏」1.查看内核版本$uname-srLinux4.15.11-1.el7.elrepo.x86_64$uname-aLinuxlocalhost.localdomain4.15.11-1.el7.elrepo.x86_64#1SMPMonMar1911:46:06EDT2018x86_64x86_64x86_64GNU/Linux$cat/pro…

    2022年10月13日
    0
  • 分享社群规划全流程sop(基础搭建、日常维…

    分享社群规划全流程sop(基础搭建、日常维…无套路,纯分享!全套社群运营文档,可学习套用相信不少做社群运营的朋友一定会出现过这种情况,微信社群或者QQ社群内的群成员不活跃,整天群里犹如一潭死水,此外还有运营目标不明确、成员不愿积极发言、大部分人入群从不说话等等问题。作为运营狗一定要学会社群规划,今天就给大家带来一份【社群规划全流程sop】,主要包含基础搭建、日常维护、增留转、互动案例等四个步骤,每个步骤都有详细的规划讲解,以及相关案例,非常值得参考学习使用。社群规划全流程sop社群规划全流程sop社…

    2022年5月9日
    66
  • 2、工厂方法模式

    2、工厂方法模式

    2021年9月13日
    51

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号