解密 加密
来源:互联网 发布:如何获取股票交易数据 编辑:程序博客网 时间:2024/05/16 06:11
package com.zxwl.common.util;import java.security.SecureRandom;import javax.crypto.Cipher;import javax.crypto.SecretKey;import javax.crypto.SecretKeyFactory;import javax.crypto.spec.DESKeySpec;import sun.misc.BASE64Decoder;public class Decryption{ private static final byte[] DES_KEY = { 115, -122, 122, -120, 119, -108, 107, -106 }; public static String decryptBasedDes(String cryptData) { String decryptedData = null; try { SecureRandom sr = new SecureRandom(); DESKeySpec deskey = new DESKeySpec(DES_KEY); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(deskey); Cipher cipher = Cipher.getInstance("DES"); cipher.init(2, key, sr); decryptedData = new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(cryptData))); } catch (Exception e) { throw new RuntimeException("解密错误,错误信息:", e); } return decryptedData; }}
package com.zxwl.common.util;import java.security.SecureRandom;import javax.crypto.Cipher;import javax.crypto.SecretKey;import javax.crypto.SecretKeyFactory;import javax.crypto.spec.DESKeySpec;import sun.misc.BASE64Encoder;public class Encryption{ private static final byte[] DES_KEY = { 115, -122, 122, -120, 119, -108, 107, -106 }; public static String encryptBasedDes(String data) { String encryptedData = null; try { SecureRandom sr = new SecureRandom(); DESKeySpec deskey = new DESKeySpec(DES_KEY); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(deskey); Cipher cipher = Cipher.getInstance("DES"); cipher.init(1, key, sr); encryptedData = new BASE64Encoder().encode(cipher.doFinal(data.getBytes())); } catch (Exception e) { throw new RuntimeException("加密错误,错误信息:", e); } return encryptedData; }}
0 0
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密、解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- 加密解密
- (Java)LeetCode-66. Plus One
- Unity3D游戏开发之SQLite让数据库开发更简单
- USACO 1.4 Mother's Milk
- centos7 无法启动网络(service network restart)错误解决办法
- HDU 4442 Physical Examination(贪心)
- 解密 加密
- P1019 单词接龙
- C编程之预处理标识符——__LINE__,__FILE__,__DATE__,__TIME__,__STDC__,#,##
- 学生信息管理系统 SSH 框架使用及范型使用
- robotium整理(二)
- open_input_file()函数介绍
- kill adb.exe
- Pseudo code for In-class QuestionExample 3: Write pseudo code that performs the following: Ask a use
- 【杂谈】蓝屏修复杂谈