springMVC,springboot整合jasypt

生成加密串

public class Encryptor {

public static void main(String\[\] args) {

BasicTextEncryptor textEncryptor = new BasicTextEncryptor();

textEncryptor.setPassword("mysalt");//自定义加密盐

String myEncryptedPassword = textEncryptor.encrypt("jdbcpasword");

System.out.println("Encrypted DB password: " + myEncryptedPassword );

}

}

jdbc连接数据库密码设置为加密的使用ENC()

复制代码
password: ENC(myEncryptedPassword )

一、.springMvc

1.引入包

复制代码
<dependency>
    <groupId>org.jasypt</groupId>
    <artifactId>jasypt-spring4</artifactId>
    <version>1.9.3</version>
</dependency>

2.applicationContext.xml添加配置

复制代码
<!--jasypt的核心配置-->

<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>
        </list>
    </property>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
<bean id="stringEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
    <property name="algorithm" value="PBEWithMD5AndDES"/>
    <property name="password" value="mysalt"/>//自定义加密盐
</bean>

二、springboot

复制代码
1.引入包
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>2.1.2</version>
</dependency>

2.启动命令增加

-Djasypt.encryptor.password=mysalt//自定义加密盐

相关推荐
骄马之死8 小时前
SpringMVC + SpringBoot 核心知识点总结
java·spring boot·后端
糖果店的幽灵9 小时前
Spring AI 从入门到精通-Embedding
人工智能·spring·embedding
郑洁文10 小时前
基于Spring Boot的流浪动物救助网站
java·spring boot·后端·毕设·流浪动物救助
指令集梦境11 小时前
Cursor + Spring Boot实战:从零写一个RESTful API
spring boot·后端·restful
宸津-代码粉碎机13 小时前
Spring AI企业级实战|从RAG优化到Agent多工具调度
java·大数据·人工智能·后端·python·spring
普通网友14 小时前
springboot之集成Elasticsearch
spring boot·后端·elasticsearch
invicinble14 小时前
关于flowable流程引擎技术栈相关
spring boot
Volunteer Technology14 小时前
深入理解HttpSecurity的设计
spring·安全框架
接着奏乐接着舞15 小时前
springcloud skywalking
spring·spring cloud·skywalking
骄马之死15 小时前
Spring 核心知识点(IOC + AOP + 事务)
java·后端·spring