当前位置:网站首页>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 !
边栏推荐
- 《畅玩NAS》家庭 NAS 服务器搭建方案「建议收藏」
- Npoi export excel and download to client
- 你的代码会说话吗?(上)
- Action interprets value. The chairman of chenglian Youpin Han attended the Guangdong Yingde flood fighting donation public welfare event
- G : 最大流问题
- Deveco studio 3.0 editor configuration tips
- 栅格矢量数据的裁剪
- Prediction of red wine quality by decision tree
- Connected to rainwater series problems
- Work study management system based on ASP
猜你喜欢

一个bug肝一周...忍不住提了issue

DevEco Studio 3.0编辑器配置技巧篇

Work study management system based on ASP

BERT为何无法彻底干掉BM25??

药物发现新方法,阿斯利康团队通过课程学习改进从头分子设计

Inftnews | technology giants accelerate their march into Web3 and metauniverse

RSLO:自监督激光雷达里程计(实时+高精度,ICRA2022)

PC Museum - familiar and strange ignorant age

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

CVPR disputes again: IBM's Chinese draft papers were accused of copying idea, who won the second place in the competition
随机推荐
干货 | 科研人的KPI怎么算,H指数和G指数是什么
Idea global search shortcut settings
2022 questions d'examen pour les cuisiniers chinois (Senior) et l'examen de simulation en ligne
你的代码会说话吗?(上)
G: maximum flow problem
验证回文串
Who is the main body of the waiting insurance record? Record in the local network security, right?
ArrayList源码解析
求解汉诺塔问题
GPS数据格式的分析与处理[通俗易懂]
Kubernetes 深入理解kubernetes(一)
ArcGIS vector center point generates rectangle and cuts TIF image for deep learning sample training
Prediction of red wine quality by decision tree
Open source invites you to participate in openinfra days China 2022. Topic collection is in progress ~
NPOI导出Excel并下载到客户端
腾讯云国际云服务器登录之后没有网络,如何排查?
Nature | mapping the interaction map of plant foliar flora to establish genotype phenotype relationship
Luogu_ P1303 A*B Problem_ High precision calculation
Four methods of thread termination
Npoi export excel and download to client