springboot整合jasypt的详细过程,
分享于 点击 26215 次 点评:255
springboot整合jasypt的详细过程,
目录
- jasypt
- springboot集成jasypt
- 1.引入maven依赖
- 2.启动类添加注解
- 3.yaml配置
- 4.加解密测试类
jasypt
保证项目中的账号密码不以明文的形式展示
springboot集成jasypt
1.引入maven依赖
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.4</version> </dependency>
2.启动类添加注解
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableEncryptableProperties public class IpSourceApplication { public static void main(String[] args) { SpringApplication.run(IpSourceApplication.class, args); } }
3.yaml配置
jasypt: encryptor: password: 02700083-9fd9-4b82-a4b4-9177e0560e92 algorithm: PBEWithMD5AndDES iv-generator-classname: org.jasypt.iv.NoIvGenerator my: username: ENC(atRC+VNwB17CQVilGftfQg==) password: ENC(Or0FKbtskiXsJlFtI23FxA==)
4.加解密测试类
import org.jasypt.util.text.BasicTextEncryptor; public class Test01 { public static void main(String[] args) { //该类的选择根据algorithm:PBEWithMD5AndDE选择的算法选择 BasicTextEncryptor encryptor = new BasicTextEncryptor(); encryptor.setPassword("02700083-9fd9-4b82-a4b4-9177e0560e92"); String encrypt = encryptor.encrypt("root"); System.out.println(encrypt); String decrypt = encryptor.decrypt(encrypt); System.out.println(decrypt); encrypt = encryptor.encrypt("mysql"); System.out.println(encrypt); decrypt = encryptor.decrypt(encrypt); System.out.println(decrypt); } }
读取配置效果
@RestController public class IpController implements InitializingBean { @Value("${my.username}") private String username; @Value("${my.password}") private String password; @Override public void afterPropertiesSet() throws Exception { System.out.println("username:"+username+",password:"+password); } }
到此这篇关于springboot整合jasypt的文章就介绍到这了,更多相关springboot整合jasypt内容请搜索3672js教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持3672js教程!
您可能感兴趣的文章:- SpringBoot集成Jasypt敏感信息加密的操作方法
- SpringBoot项目使用jasypt加解密的方法
- springboot 项目使用jasypt加密数据源的方法
- Jasypt对SpringBoot配置文件加密
- SpringBoot项目整合jasypt实现过程详解
- SpringBoot 集成 Jasypt 对数据库加密以及踩坑的记录分享
- 在SpringBoot中通过jasypt进行加密解密的方法
用户点评