当前位置:网站首页>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 !
边栏推荐
猜你喜欢
随机推荐
欧拉恒等式:数学史上的真正完美公式!
ArcGIS vector center point generates rectangle and cuts TIF image for deep learning sample training
Native JS implements drag and drop of page elements
Cat dog queue
Only four breakthrough Lenovo smart Summer Palace in mainland China won the "IDC Asia Pacific Smart City Award in 2022"
2022年焊工(技师)考试题库模拟考试平台操作
坐拥755万开发者的中国开源,进度几何?
你的代碼會說話嗎?(上)
有效提高绩效面谈的10个关键点
Regular matching numbers, English and English symbols
做一个墨水屏电子钟,炫酷!
SPI接口简介-Piyu Dhaker
[binary tree] allocate coins in the binary tree
Nature | mapping the interaction map of plant foliar flora to establish genotype phenotype relationship
PostgreSQL surpasses MySQL
《畅玩NAS》家庭 NAS 服务器搭建方案「建议收藏」
外贸SEO 站长工具
【二叉树】在二叉树中分配硬币
go数组与切片,[]byte转string[通俗易懂]
Why can't Bert completely kill the BM25??








