当前位置: 首页 > news >正文

免费网站开发框架西安网站seo技术

免费网站开发框架,西安网站seo技术,网站 繁体 js,网站做接口文章目录 前言一、集成 Jasypt1. pom 依赖2. yml 依赖 3. 加密工具类3. 使用二、常见问题1. application.yml 失效问题2. 配置热更新失败问题 前言 jasypt 官方地址:https://github.com/ulisesbocchio/jasypt-spring-boot Jasypt可以为Springboot加密的信息很多&a…

文章目录

  • 前言
  • 一、集成 Jasypt
    • 1. pom 依赖
    • 2. yml 依赖
  • 3. 加密工具类
  • 3. 使用
  • 二、常见问题
    • 1. application.yml 失效问题
    • 2. 配置热更新失败问题


前言

jasypt 官方地址:https://github.com/ulisesbocchio/jasypt-spring-boot

Jasypt可以为Springboot加密的信息很多,主要有:

  1. System Property 系统变量。
  2. Envirnment Property 环境变量。
  3. Command Line argument 命令行参数。
  4. Application.properties 应用配置文件。
  5. Yaml properties 应用配置文件。
  6. other custom property sources 其它配置文件。

一、集成 Jasypt

1. pom 依赖

<!-- jasypt(yml加密) -->
<dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>3.0.5</version>
</dependency>

2. yml 依赖

jasypt:encryptor:password: encpassword # 加密盐值(自定义)algorithm: PBEWithMD5AndDES # 加密算法(3.0.5以下版本默认PBEWithMD5AndDES,即DES加密算法-32位密文;3.0.5及以上版本默认PBEWITHHMACSHA512ANDAES_256,即AES加密算法-64位密文)iv-generator-classname: org.jasypt.iv.NoIvGenerator # 加密偏移生成器

3. 加密工具类

使用如下工具类,对密码进行加密获取密文。

import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;/*** jasypt(yml加密)工具** @author whiteen* @date 2024-06-20 00:00:00*/
@Slf4j
public class JasyptUtil {/*** DES加密** @param original 待加密内容* @param password 加密盐值* @return 加密密文* @author whiteen* @date 2024-06-20 00:00:00*/public static String encryptByDes(String original, String password) {StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();SimpleStringPBEConfig config = new SimpleStringPBEConfig();// 设置盐值config.setPassword(password);config.setAlgorithm("PBEWithMD5AndDES");config.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator");encryptor.setConfig(config);// 加密return encryptor.encrypt(original);}/*** AES加密** @param original 待加密内容* @param password 加密盐值* @return 加密密文* @author whiteen* @date 2024-06-20 00:00:00*/public static String encryptByAes(String original, String password) {StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();SimpleStringPBEConfig config = new SimpleStringPBEConfig();// 设置盐值config.setPassword(password);config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");encryptor.setConfig(config);// 加密return encryptor.encrypt(original);}/*** DES解密** @param original 待解密内容* @param password 加密盐值* @return 加密明文* @author whiteen* @date 2024-06-20 00:00:00*/public static String decryptByDes(String original, String password) {StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();SimpleStringPBEConfig config = new SimpleStringPBEConfig();// 设置盐值config.setPassword(password);config.setAlgorithm("PBEWithMD5AndDES");config.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator");encryptor.setConfig(config);// 解密return encryptor.decrypt(original);}/*** AES解密** @param original 待解密内容* @param password 加密盐值* @return 加密明文* @author whiteen* @date 2024-06-20 00:00:00*/public static String decryptByAes(String original, String password) {StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();SimpleStringPBEConfig config = new SimpleStringPBEConfig();// 设置盐值config.setPassword(password);config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");encryptor.setConfig(config);// 解密return encryptor.decrypt(original);}public static void main(String[] args) {// 待加密内容String original = "original";// 加密盐值String password = "encpassword";// DES加密String encryptedDes = encryptByDes(original, password);log.info("DES密⽂: {}", encryptedDes);// DES解密String decryptedDes = decryptByDes(encryptedDes, password);log.info("DES明⽂: {}", decryptedDes);// AES加密String encryptedAes = encryptByAes(original, password);log.info("AES密⽂: {}", encryptedAes);// AES解密String decryptedAes = decryptByAes(encryptedAes, password);log.info("AES明⽂: {}", decryptedAes);}}

3. 使用

password: ENC(${ORACLE_PWD:password})

二、常见问题

1. application.yml 失效问题

如果你的项目存在 boostrap.yml 配置文件,在引入 jasypt-spring-boot-starter 之后,发现 application.yml 与 application-dev.yml 配置没有生效,需要在 boostrap.yml 中设置 jasypt.encryptor.bootstrap 属性为 false,禁用对 boostrap 配置文件的加密支持,就可以解决 application.yml 与 application-dev.yml 配置失效的问题。

说明:
当 jasypt 和 springcloud 一起使用时,bootstrap 的配置会失效。追踪代码发现,spring 在启动 bootstrap 容器后,当把 bootstrap 容器的 environment 合并到子容器时,只同步了 OriginTrackedMapPropertySource 类型 BootstrapApplicationListener,此时所有的 PropertySource 都已经被包装为 EncryptablePropertySourceWrapper,所以会导致 bootstrap 的配置不会合并到子容器。

2. 配置热更新失败问题

在 yml 配置文件中设置环境变量报错。

参考 apollo 跟 jasypt-spring-boot-2.1.0.jar 不兼容问题: https://github.com/apolloconfig/apollo/issues/2162

升级 jasypt-spring-boot-starter 到 3.0.5 及以上版本可以解决配置热更新问题,再新增 algorithm 和 iv-generator-classname 两个配置即可:

<!-- jasypt(yml加密) -->
<dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>3.0.5</version>
</dependency>
jasypt:encryptor:password: encpassword # 加密盐值(自定义)algorithm: PBEWithMD5AndDES # 加密算法(3.0.5以下版本默认PBEWithMD5AndDES,即DES加密算法-32位密文;3.0.5及以上版本默认PBEWITHHMACSHA512ANDAES_256,即AES加密算法-64位密文)iv-generator-classname: org.jasypt.iv.NoIvGenerator # 加密偏移生成器

这样就可以在 yml 配置文件中设置环境变量:

password: ENC(${ORACLE_PWD:BBO5rGF40i+Sg5oG36MT5aEwpdrOe5f2})
http://www.hkea.cn/news/599536/

相关文章:

  • 一家专门做开网店的网站北京seo专员
  • 专业企业网站搭建服务头条权重查询
  • 去哪儿网站上做民宿需要材料免费的黄冈网站有哪些平台
  • 网站建设网现在推广什么app最挣钱
  • 嘉兴装修公司做网站安装百度到桌面
  • 电商网站特点外贸营销网站建站
  • 上海市住房城乡建设管理委员会网站网络营销软文范例大全800
  • 莱芜区政协网站做网络优化的公司排名
  • 太原网站建设开发公司电商运营基本知识
  • php做企业网站seo网站推广企业
  • 万网网站备案授权书免费发布推广信息的b2b
  • 乡镇可以做门户网站seo是什么意思职业
  • 建设银行网站优点做个公司网站大概多少钱
  • 网站标题的设置方法哪家建设公司网站
  • 网站空间托管电商平台的营销方式
  • 网站制作专业的公司有哪些seo网站编辑是做什么的
  • wordpress 分栏seo怎么优化简述
  • php网站开发 多少钱推广方案策划
  • 芜湖做网站公司广州seo好找工作吗
  • 做网站找客户百度竞价推广公司
  • 深圳网站建设怎么办互联网营销的优势
  • 课程网站开发背景网站推广的几种方法
  • 商城网站建设模板一份完整的营销策划方案
  • 推广网站建设网站权重查询工具
  • t型布局网站怎么做建设网官方网站
  • 哪个建设网站推广竞价托管公司
  • 网站建设傲seo网站是什么意思
  • 卢氏住房和城乡建设厅网站聚名网
  • 山东网站建设电话长沙靠谱的关键词优化
  • 山东营销型网站ip网站查询服务器