Spring Boot 整合 Jasypt 加解密实战

Jasypt 是一个用于加解密的 Java 库,可以快速集成到 Spring Boot 项目中实现自动解密功能。

本篇文章通过一个数据库密码的加解密场景,详细介绍了 Jasypt 的使用步骤、具体开发过程及代码分析、测试步骤等等,贴出完整的代码并提供下载。

你将会获得以下知识:

  1. Jasypt 使用步骤
  2. Jasypt 完整代码
  3. Jasypt 测试步骤

适合人群:Java 初中级开发。

前言

我所在项目组刚接到一个密码加密需求,具体需求是把配置文件所有明文的密码都换成密文,经分析后选用 Jasypt 来实现加解密。

本篇文章通过一个数据库密码的加解密场景,详细介绍了 Jasypt 的使用步骤、具体开发过程及代码分析、测试步骤等等,贴出完整的代码并提供下载。

具体开发过程及代码分析

代码结构

在这里插入图片描述

pom.xml 文件配置

下面配置是工程需要使用的所有 jar 和 maven 打包策略,必须引入 jasypt-spring-boot-starter,代码如下:

	<?xml version="1.0" encoding="UTF-8"?>
	<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
		<modelVersion>4.0.0</modelVersion>
		<parent>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-parent</artifactId>
			<version>2.5.6</version>
			<relativePath/> <!-- lookup parent from repository -->
		</parent>
		<groupId>com.example</groupId>
		<artifactId>demo-jasypt</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<name>demo-jasypt</name>
		<description>Demo project for Spring Boot</description>
		<properties>
			<java.version>1.8</java.version>
		</properties>
		<dependencies>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-starter</artifactId>
			</dependency>
	
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-starter-test</artifactId>
				<scope>test</scope>
			</dependency>
	
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-starter-web</artifactId>
			</dependency>
	
			<dependency>
				<groupId>com.github.ulisesbocchio</groupId>
				<artifactId>jasypt-spring-boot-starter</artifactId>
				<version>3.0.2</version>
			</dependency>
	
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-starter-data-jpa</artifactId>
			</dependency>
			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<scope>runtime</scope>
			</dependency>
	
		</dependencies>
	
		<build>
			<plugins>
				<plugin>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-maven-plugin</artifactId>
				</plugin>
			</plugins>
		</build>
	
	</project>

点击这里阅读全文

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多鱼的夏天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值