当前位置:网站首页>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 .
边栏推荐
- Binder communication process and servicemanager creation process
- Parsing XML using Dom4j
- DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告
- APICloud Studio3 API管理与调试使用教程
- JS to determine whether an element exists in the array (four methods)
- 【MySQL 使用秘籍】一網打盡 MySQL 時間和日期類型與相關操作函數(三)
- 前缀、中缀、后缀表达式「建议收藏」
- “百度杯”CTF比赛 九月场,Web:SQL
- asp.net 读取txt文件
- 多人合作项目查看每个人写了多少行代码
猜你喜欢

DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告

Can and can FD

DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告

Nantong online communication group

Could not set property ‘id‘ of ‘class XX‘ with value ‘XX‘ argument type mismatch 解决办法

Android本地Sqlite数据库的备份和还原

How to apply the updated fluent 3.0 to applet development
![[深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation](/img/70/6de0346df8527af6c88db1ff89947b.png)
[深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation

FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze

What are the private addresses
随机推荐
从外卖点单浅谈伪需求
Usage, installation and use of TortoiseSVN
Address book (linked list implementation)
Shandong University Summer Training - 20220620
Jenkins installation
Prefix, infix, suffix expression "recommended collection"
Go string operation
百度杯”CTF比赛 2017 二月场,Web:爆破-2
Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
leetcode 10. Regular Expression Matching 正则表达式匹配 (困难)
【 script secret pour l'utilisation de MySQL 】 un jeu en ligne sur l'heure et le type de date de MySQL et les fonctions d'exploitation connexes (3)
FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
restTemplate详解
一文详解ASCII码,Unicode与utf-8
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
这18个网站能让你的页面背景炫酷起来
Binder通信过程及ServiceManager创建过程
同事半个月都没搞懂selenium,我半个小时就给他整明白!顺手秀了一波爬淘宝的操作[通俗易懂]
“百度杯”CTF比赛 九月场,Web:SQL
#从源头解决# 自定义头文件在VS上出现“无法打开源文件“XX.h“的问题