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

相关推荐
huaweichenai3 小时前
spring boot 实现file文件上传
java·spring boot·后端
VX_bysjlw9853 小时前
数码设备销售网站设计与实现39138-计算机毕设原创(免费领源码+带部署教程)
java·vue.js·spring boot·mysql·tomcat·mybatis·idea
桃西西呀3 小时前
Spring AI Alibaba 之七:我没写一行 tracing 埋点,Agent 每一步却被 Micrometer 看得清清楚楚
人工智能·spring·llm
桃西西呀3 小时前
Spring AI Alibaba 之八:我让 Agent 直接执行 shell 命令,它却读到了目录里的密钥,沙箱到底防住了什么
人工智能·spring·llm
code_slave(码畜)4 小时前
微服务架构落地:消息队列架构设计(下篇)——消息堆积、死信治理与集群监控告警实战
spring boot·spring cloud·微服务·云原生·中间件·架构
~光~~5 小时前
【嵌入式linux学习】Cache 策略:Write-Through / Write-Back + Allocation
linux·学习·spring
霸道流氓气质6 小时前
OpenTelemetry 入门与实战:Java Agent、Spring Boot Starter与LLM调用追踪示例
java·开发语言·spring boot
m0_587383006 小时前
24 小时自助健身房系统软件开发实战指南与案例解析
java·spring boot·spring·系统架构·需求分析
爱编程的小白L6 小时前
基于SpringBoot+Vue的医院门诊排队叫号系统的设计与实现
spring boot