当前位置:网站首页>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 .
边栏推荐
- Go string operation
- go 字符串操作
- 【Hot100】33. Search rotation sort array
- Integer = = the comparison will unpack automatically. This variable cannot be assigned empty
- 53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
- How to apply the updated fluent 3.0 to applet development
- js判断数组中是否存在某个元素(四种方法)
- [MySQL usage Script] catch all MySQL time and date types and related operation functions (3)
- Write API documents first or code first?
- 时钟周期
猜你喜欢
Godson 2nd generation burn PMON and reload system
What is a network port
TortoiseSVN使用情形、安装与使用
redis6事务和锁机制
Fragmented knowledge management tool memos
SAE international strategic investment geometry partner
go 数组与切片
Intranet penetration tool NetApp
STM32 reverse entry
[daily question] 1200 Minimum absolute difference
随机推荐
restTemplate详解
jenkins安装
华为推送服务内容,阅读笔记
go 数组与切片
精彩速递|腾讯云数据库6月刊
【MySQL 使用秘籍】一网打尽 MySQL 时间和日期类型与相关操作函数(三)
JS to determine whether an element exists in the array (four methods)
leetcode 10. Regular Expression Matching 正则表达式匹配 (困难)
[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
法国学者:最优传输理论下对抗攻击可解释性探讨
APICloud Studio3 WiFi真机同步和WiFi真机预览使用说明
C object storage
Jenkins installation
从外卖点单浅谈伪需求
Talk about seven ways to realize asynchronous programming
Prefix, infix, suffix expression "recommended collection"
49. 字母异位词分组:给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
Lb10s-asemi rectifier bridge lb10s
多人合作项目查看每个人写了多少行代码