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

相关推荐
【D'accumulation】17 分钟前
令牌主动失效机制范例(利用redis)注释分析
java·spring boot·redis·后端
2401_8543910827 分钟前
高效开发:SpringBoot网上租赁系统实现细节
java·spring boot·后端
wxin_VXbishe36 分钟前
springboot合肥师范学院实习实训管理系统-计算机毕业设计源码31290
java·spring boot·python·spring·servlet·django·php
OEC小胖胖1 小时前
Spring Boot + MyBatis 项目中常用注解详解(万字长篇解读)
java·spring boot·后端·spring·mybatis·web
2401_857617621 小时前
SpringBoot校园资料平台:开发与部署指南
java·spring boot·后端
quokka561 小时前
Springboot 整合 logback 日志框架
java·spring boot·logback
计算机学姐1 小时前
基于SpringBoot+Vue的在线投票系统
java·vue.js·spring boot·后端·学习·intellij-idea·mybatis
落落落sss2 小时前
MybatisPlus
android·java·开发语言·spring·tomcat·rabbitmq·mybatis
2401_854391083 小时前
Spring Boot大学生就业招聘系统的开发与部署
java·spring boot·后端
杨荧3 小时前
【JAVA开源】基于Vue和SpringBoot的洗衣店订单管理系统
java·开发语言·vue.js·spring boot·spring cloud·开源