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

相关推荐
NE_STOP12 小时前
springMVC-HTTP消息转换器与文件上传、下载、异常处理
spring
洋洋技术笔记14 小时前
Spring Boot配置管理最佳实践
spring boot
用户8307196840821 天前
Spring Boot 项目中日期处理的最佳实践
java·spring boot
JavaGuide1 天前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
玹外之音1 天前
Spring AI MCP 实战:将你的服务升级为 AI 可调用的智能工具
spring·ai编程
来一斤小鲜肉1 天前
Spring AI入门:第一个AI应用跑起来
spring·ai编程
NE_STOP2 天前
springMVC-常见视图组件与RESTFul编程风格
spring
大道至简Edward2 天前
Spring Boot 2.7 + JDK 8 升级到 Spring Boot 3.x + JDK 17 完整指南
spring boot·后端
洋洋技术笔记2 天前
Spring Boot启动流程解析
spring boot·后端
怒放吧德德2 天前
Spring Boot 实战:RSA+AES 接口全链路加解密(防篡改 / 防重放)
java·spring boot·后端