当前位置:网站首页>Jasypt configuration file encryption | quick start | actual combat
Jasypt configuration file encryption | quick start | actual combat
2022-07-05 13:36:00 【Bulst】
List of articles
Jasypt (Java Simplified Encryption) It's a java library , It allows developers to add basic encryption capabilities to projects at minimal cost , There is no need to understand the working principle of cryptography .
Introduce dependencies
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
take effect
If it's for spring boot Project configuration file encryption , No additional configuration is required , Start... On the class @SpringBootApplication It will be automatically injected into the program , Make it effective .
Scope
Specify the scope of the configuration file , Other configuration files are not affected jasypt influence
@Configuration
@EncryptablePropertySources({
@EncryptablePropertySource("classpath:sentinel-1.properties"),
@EncryptablePropertySource("classpath:sentinel-2.properties")
})
application
Tool class
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
/** * @author issavior */
public class JasyptUtil {
/** * org.jasypt.encryption.StringEncryptor object */
private static StringEncryptor stringEncryptor = null;
public static StringEncryptor getInstance(String secretKey) throws Exception {
if (secretKey == null || secretKey.trim().equals("")) {
System.out.println(" The secret key cannot be empty !");
throw new Exception("org.jasypt.encryption.StringEncryptor The secret key cannot be empty !");
}
if (stringEncryptor == null) {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
// This secret key must be defined by ourselves
config.setPassword(secretKey);
config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName("SunJCE");
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
stringEncryptor = encryptor;
}
return stringEncryptor;
}
public static void main(final String[] args) {
// Secret key string
String secretKey = "[email protected]#";
// Plaintext password to be encrypted
String pass = "123456";
try {
StringEncryptor stringEncryptor = JasyptUtil.getInstance(secretKey);
String encryptPass = stringEncryptor.encrypt(pass);
System.out.println("【" + pass + "】 Encrypted into 【" + encryptPass + "】");
String clearPass = stringEncryptor.decrypt(encryptPass);
System.out.println("【" + encryptPass + "】 Decrypted as 【" + clearPass + "】");
} catch (Exception e) {
e.printStackTrace();
}
}
}
To configure
jasypt:
encryptor:
password: 123[email protected]#
my:
# Must use ENC() wrap up , such jasypt To recognize this password, decrypt it and then send it to the application
msg: ENC(PwyGulNOC9YERAC9A6zpH8Da1tn50dtgJ1XBqygkdNoBTkjmENd+F5yJJMp4sthf)
List of properties

Advanced
Its internal properties can be rewritten , Include ENC() etc. .
Yes, of course , Your salt and password must be stored separately , in other words , The encrypted password is configured in the configuration file , The encrypted salt can be placed on the startup parameters .
边栏推荐
- 【MySQL 使用秘籍】一網打盡 MySQL 時間和日期類型與相關操作函數(三)
- [server data recovery] a case of RAID5 data recovery stored in a brand of server
- go map
- 时钟周期
- 53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
- How to choose note taking software? Comparison and evaluation of notion, flowus and WOLAI
- What is a network port
- 私有地址有那些
- Write macro with word
- Jenkins installation
猜你喜欢

STM32 reverse entry

记录一下在深度学习-一些bug处理

What is a network port

C object storage

redis6事务和锁机制

TortoiseSVN使用情形、安装与使用

ASEMI整流桥HD06参数,HD06图片,HD06应用

先写API文档还是先写代码?

Don't know these four caching modes, dare you say you understand caching?

Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
随机推荐
go 指针
JS to determine whether an element exists in the array (four methods)
How to apply the updated fluent 3.0 to applet development
Get you started with Apache pseudo static configuration
Win10——轻量级小工具
Can and can FD
山东大学暑期实训一20220620
【Hot100】33. Search rotation sort array
南理工在线交流群
What happened to the communication industry in the first half of this year?
Multi person cooperation project to see how many lines of code each person has written
“百度杯”CTF比赛 九月场,Web:SQL
Talk about seven ways to realize asynchronous programming
#从源头解决# 自定义头文件在VS上出现“无法打开源文件“XX.h“的问题
【Hot100】34. Find the first and last positions of elements in a sorted array
从外卖点单浅谈伪需求
Idea set method annotation and class annotation
百度杯”CTF比赛 2017 二月场,Web:爆破-2
Jenkins installation
FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze