J2EE配置文件加密
public class SecurityHelper
{/*** 加密* @param text 待加密内容* @param key 密钥* @return 密文*/public static String DESEncrypt(String text, String key){try{// 进行3-DES加密后的内容的字�?DESedeKeySpec dks = new DESedeKeySpec(key.getBytes());SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");SecretKey skey = keyFactory.generateSecret(dks);Cipher cipher = Cipher.getInstance("DESede");cipher.init(Cipher.ENCRYPT_MODE, skey);byte[] encryptedData = cipher.doFinal(text.getBytes());// 进行3-DES加密后的内容进行BASE64编码BASE64Encoder base64en = new BASE64Encoder();return base64en.encode(encryptedData);} catch (Exception e){e.printStackTrace();return text;}}/*** 解密* @param text 待解密内容* @param key 密钥* @return*/public static String DESDecrypt(String text, String key){try{// 进行3-DES加密后的内容进行BASE64解码BASE64Decoder base64Decode = new BASE64Decoder();byte[] base64DValue = base64Decode.decodeBuffer(text);// 进行3-DES解密后的内容的字�?DESedeKeySpec dks = new DESedeKeySpec(key.getBytes());SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");SecretKey skey = keyFactory.generateSecret(dks);Cipher cipher = Cipher.getInstance("DESede");cipher.init(Cipher.DECRYPT_MODE, skey);byte[] encryptedData = cipher.doFinal(base64DValue);return new String(encryptedData);} catch (Exception e){e.printStackTrace();return text;}}}
public class FileEncrypt {public static void Encrypt(){InputStream inputStream;try {inputStream = new FileInputStream("src/main/resources/config.properties");FileOutputStream fos = new FileOutputStream("src/main/resources/configEncrypt.properties");Scanner scanner = new Scanner(inputStream, "UTF-8");String text = scanner.useDelimiter("\\A").next();scanner.close();String encode = SecurityHelper.DESEncrypt(text, "as!2e4b4%1b6e2&ba5.-011b?720f-=+");System.out.println("============================加密前=============================");System.out.println(text);System.out.println("============================加密后=============================");System.out.println(encode);fos.write(encode.getBytes("UTF-8"));fos.flush();fos.close();} catch (Exception e) {e.printStackTrace();}}public static void DEcrypt(){InputStream inputStream;try {inputStream = new FileInputStream("src/main/resources/configEncrypt.properties");FileOutputStream fos = new FileOutputStream("src/main/resources/configDecrypt.properties");Scanner scanner = new Scanner(inputStream, "UTF-8");String text = scanner.useDelimiter("\\A").next();scanner.close();String code = SecurityHelper.DESDecrypt(text, "as!2e4b4%1b6e2&ba5.-011b?720f-=+");System.out.println("============================解密前=============================");System.out.println(text);System.out.println("============================解密后=============================");System.out.println(code);fos.write(code.getBytes("UTF-8"));fos.flush();fos.close();} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args){Encrypt();DEcrypt();}
}
推荐一个淘宝返利网,每天9块9包邮还返利。现在登录还有9元支付宝红包送你哦!taofen8.com/invite/ADL56II0
转载于:https://blog.51cto.com/owen563/1287692
J2EE配置文件加密相关推荐
- php 配置文件加密工具类,SpringBoot集成Jasypt安全框架以及配置文件内容加密(代码示例)...
本篇文章给大家带来的内容是关于SpringBoot集成Jasypt安全框架以及配置文件内容加密(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 我们在SpringBoot项 ...
- ASP.NET 配置文件加密
众所周知,web.config可以存储包括数据库链接在内的众多信息,所以为配置文件加密有时候就显得必要了. 1.加密前的配置文件如下: Web.config 1 <?xml version=&q ...
- NET2.0配置文件加密(WEBWindows)
posted on 2006年5月6日 15:42 由 吴頔 WEB篇 网上已经有很多文章提到: ASP.NET 2.0加密Web.config 配置文件 Keeping se ...
- java 配置文件加密_Spring cloud config 配置文件加密方式
前言 我们会使用git来保存我们项目的配置文件,但是文件中总有一些敏感数据,对于这些敏感数据我们通常需要给它加密,加密通常有两种加密方式,一种是对称加密,一种是非对称加密,对称加密简单方便,但是安全性 ...
- SpringBoot 配置文件加密的两种方式
SpringBoot配置文件加密的两种方式 jasypt使用方式 用法一: 1.Application.java上增加注解@EnableEncryptableProperties(jasypt-spr ...
- 配置文件加密(Jasypt的简单使用)
title: 配置文件加密(Jasypt的简单使用) categories: Jasypt tags: Jasypt 需求引入 当我们需要对SpringBoot项目的配置文件中的信息进行加密时,如数据 ...
- Springboot之Jasypt配置文件加密/解密
Jasypt配置文件加密/机密 一.Jasypt介绍 二.Springboot整合Jasypt 2.1 环境配置 2.2 添加依赖 2.3 添加Jasypt配置 2.4 编写加/解密工具类 2.5 修 ...
- spring boot 配置文件加密数据库用户名/密码
这篇文章为大家分享spring boot的配置文件properties文件里面使用经过加密的数据库用户名+密码,因为在自己做过的项目中,有这样的需求,尤其是一些大公司,或者说上市公司,是不会把这些敏感 ...
- Java工作笔记-Spring boot中配置文件加密(Jasypt的使用)
Jasypt Spring Boot提供了Spring Boot应用程序配置文件的加密.有下面3种方式在项目中集成jasypt-spring-boot: 1. 在classpath中添加jasypt- ...
- SpringBoot配置文件加密
文章目录 1 场景 2 加密方式 3 加密过程 3.1 maven依赖 3.2 配置加密密钥 3.2.1 开发环境 3.2.2 生产环境 3.3 加密 3.4 配置密文 1 场景 SpringBoot ...
最新文章
- uva 1416 (SPFA) **月赛第E题的原题**
- 借助JRebel使Tomcat支持热部署
- mysql insert 字符集_有关 MySQL 字符集的注意事项-爱可生
- C#基础 基本语法4
- 使用DOM动态创建标签
- 王昶衡(帮别人名字作诗)
- 在mac上用文本编辑器写python_Mac开源文本编辑器CotEditor
- 工作资讯003---甘特图
- pp-tracking ubuntu 18.04使用GPU推理出现Segmentation fault
- 用php绘制空心圆,html5使用canvas画空心圆与实心圆_html5教程技巧
- 自己的 并查集 模板
- scala(13)-----集合(Collection)-------列表
- Toshiba Folio + CWM +CM
- 如何区分电压串联负反馈电路和电流串联负反馈电路
- Word中的公式对齐
- c++笔记③1109
- java程序设计实验报告代写_代写file I/O作业、代写java Scanner I/O程序、代写java编程作业、代做java实验报告...
- 洛谷入门1【顺序结构】题单题解
- 【vsftpd】配置
- 《Python编程 从入门到实践》第八章 ——函数习题
热门文章
- 1万小时后,我从外包走进了字节跳动,现在出了一本书,文末送书!
- 从图形界面到会话界面
- ie8打不开mysql登录_Win7下IE8无法打开https类型的网站解决方法笔记
- java 微信图片上传_后台Java代码加前端微信小程序实现图片上传案例(学习)
- android日期时间的获取与时差计算
- 2020 EBC徒步功课做好 好好工作心态
- 如何学会学习——读唐老师博文有感
- ie打开本地html页面慢,ie11 第一次浏览jquery+CSS3网页时候延时3秒
- cs1.6服务器修改游戏类型,如何自己架设CS1.6服务器?
- 模乘与Montgomery 模乘