当前位置:网站首页>Configuration file encryption (simple use of jasypt)
Configuration file encryption (simple use of jasypt)
2022-06-28 14:13:00 【Hua Weiyun】
title: Profile encryption (Jasypt Simple use )
categories: Jasypt
tags: Jasypt
Demand introduction
When we need to be right SpringBoot When encrypting the information in the configuration file of the project , Such as database password, etc , Now we can use it Jasypt To achieve .
Solution
First step , introduce Jasypt rely on
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.0.0</version></dependency>The second step , Write a tool class
JasyptUtils:
package com.keafmd.springdemo.utils;import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;/** * Keafmd * * @ClassName: JasyptUtils * @Description: * @author: Cowherd Conan * @date: 2022-04-25 11:18 */public class JasyptUtils { /** * Jasypt Generate encrypted results * * @param password The encryption password set in the configuration file jasypt.encryptor.password * @param value Value to be encrypted * @return */ public static String encryptPwd(String password, String value) { PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor(); encryptOr.setConfig(cryptOr(password)); String result = encryptOr.encrypt(value); return result; } /** * Decrypt * * @param password The encryption password set in the configuration file jasypt.encryptor.password * @param value Ciphertext to be decrypted * @return */ public static String decyptPwd(String password, String value) { PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor(); encryptOr.setConfig(cryptOr(password)); String result = encryptOr.decrypt(value); return result; } /** * @param password salt * @return */ public static SimpleStringPBEConfig cryptOr(String password) { SimpleStringPBEConfig config = new SimpleStringPBEConfig(); config.setPassword(password); config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM); config.setKeyObtentionIterations("1000"); config.setPoolSize("1"); config.setProviderName(null); config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); config.setStringOutputType("base64"); return config; } public static void main(String[] args) { // encryption // Replace the salt value with your familiar password , This password is the decryption key , It needs to be kept properly . // The salt value also needs to be written into the configuration file in the third step System.out.println(encryptPwd("keafmd", "123456")); }}The third step , Modify the configuration file
- Write the salt value into the configuration file
- Replace the plaintext password with the ciphertext generated by the tool class , And use ENC() Wrapped
eg:
# Connect to data source spring: datasource: username: root password: ENC(aXcmM77CmYgj67mBxQgI2A==) url: jdbc:mysql://XXXX:XX/tt?useUnicode=true&characterEncoding=UTF-8&useSSL=false jasypt: encryptor: password: keafmdThe above is the configuration file encryption (Jasypt Simple use ) The whole content of
Copyright notice :
Original Blogger : Cowherd Conan
Personal blog links :https://www.keafmd.top/
If it helps you , Thank you for clicking on == One key, three links == Support !
[ ha-ha ][ Huai Quan ]

come on. !
Joint efforts !
Keafmd
You can see it here , You know the following , Let's make progress together !
边栏推荐
- Navicat Premium 16 永久破解激活工具及安装教程(亲测可用)
- A queue of two stacks
- Npoi export excel and download to client
- 有效提高绩效面谈的10个关键点
- Prediction of red wine quality by decision tree
- Jupyter notebook中添加虚拟环境
- Work study management system based on ASP
- PostgreSQL surpasses MySQL
- 3. Overall UI architecture of the project
- Build a learning environment
猜你喜欢

A bug liver a week I can't help mentioning issue

Kubernetes in-depth understanding of kubernetes (I)

接雨水系列问题

How to count dimensions of foreign trade E-mail Promotion

外贸邮件推广怎么统计维度

Yii2 writing the websocket service of swoole

If a programmer goes to prison, will he be assigned to write code?

PCB understand Wang, are you? I am not

基于ASP的勤工俭学管理系统

New drug discovery methods, AstraZeneca team improves ab initio molecular design through course learning
随机推荐
G : 最大流问题
Black apple installation tutorial OC boot "suggestions collection"
Kubernetes 深入理解kubernetes(一)
China Radio and television 5g package is coming, lower than the three major operators, but not as low as expected
NFT digital collection system development (3D modeling economic model development case)
力扣解法汇总522-最长特殊序列 II
(原创)【MAUI】一步一步实现“悬浮操作按钮”(FAB,Floating Action Button)
Tencent cloud international ECS has no network after logging in. How to troubleshoot?
设计一个有getMin功能的栈
基于MATLAB的混沌数字图像加密技术研究与仿真实现
A queue of two stacks
New drug discovery methods, AstraZeneca team improves ab initio molecular design through course learning
外贸SEO 站长工具
How fragrant! The most complete list of common shortcut keys for pychar!
3. Overall UI architecture of the project
What does VPS do? What are the famous brands? What is the difference with ECS?
推荐四款可视化工具,解决 99% 的可视化大屏项目!
从小小线虫谈起——溯源神经系统进化,开启生命模拟
ArrayList源码解析
Websocket automatically disconnects in 1 minute