当前位置:网站首页>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 .
边栏推荐
- #从源头解决# 自定义头文件在VS上出现“无法打开源文件“XX.h“的问题
- 一文详解ASCII码,Unicode与utf-8
- “百度杯”CTF比赛 九月场,Web:Upload
- "Baidu Cup" CTF competition in September, web:upload
- Shuttle INKWELL & ink components
- A detailed explanation of ASCII code, Unicode and UTF-8
- C object storage
- Redis6 master-slave replication and clustering
- My colleague didn't understand selenium for half a month, so I figured it out for him in half an hour! Easily showed a wave of operations of climbing Taobao [easy to understand]
- stm32逆向入门
猜你喜欢
MMSeg——Mutli-view时序数据检查与可视化
Go array and slice
Android本地Sqlite数据库的备份和还原
Idea设置方法注释和类注释
一文详解ASCII码,Unicode与utf-8
【每日一题】1200. 最小绝对差
Nantong online communication group
The real king of caching, Google guava is just a brother
运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
[深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation
随机推荐
[深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation
Programmer growth Chapter 8: do a good job of testing
How to apply the updated fluent 3.0 to applet development
【Hot100】34. Find the first and last positions of elements in a sorted array
“百度杯”CTF比赛 九月场,Web:Upload
redis6数据类型及操作总结
AVC1与H264的区别
restTemplate详解
Can and can FD
A detailed explanation of ASCII code, Unicode and UTF-8
通讯录(链表实现)
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明
“百度杯”CTF比赛 九月场,Web:SQL
Lb10s-asemi rectifier bridge lb10s
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
With 4 years of working experience, you can't tell five ways of communication between multithreads. Dare you believe it?
Intranet penetration tool NetApp
法国学者:最优传输理论下对抗攻击可解释性探讨
go map
What is a network port