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//自定义加密盐

相关推荐
tant1an28 分钟前
Spring Boot 基础入门:从核心配置到 SSMP 整合实战
java·数据库·spring boot·sql·spring
xiaoye37081 小时前
某大厂java面试题二面20260313
java·开发语言·spring
矩阵科学2 小时前
【Spring 原理系列】手搓一个Spring框架
spring
彭于晏Yan2 小时前
Springboot实现微服务监控
spring boot·后端·微服务
小江的记录本2 小时前
【Spring Boot—— .yml(YAML)】Spring Boot中.yml文件的基础语法、高级特性、实践技巧
xml·java·spring boot·后端·spring·spring cloud·架构
稻草猫.2 小时前
SpringBoot日志全解析:从调试到持久化
java·开发语言·spring boot·java-ee·idea
老友@3 小时前
接口调用的演进史——从“发 HTTP 请求”到“可治理的系统能力
spring boot·后端·架构
深蓝轨迹3 小时前
IDEA 中 Spring Boot 配置文件的自动提示消失(无法扫描配置文件)的完整解决方案
java·spring boot·intellij-idea
zb200641204 小时前
Redis的Spring配置
数据库·redis·spring