RES加密
来源:互联网 发布:windows正版好处 编辑:程序博客网 时间:2024/04/29 05:38
- 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;
- import sun.misc.BASE64Encoder;
- public class DESHelper {
- /**
- * 加密解密接口
- * @param data 数据
- * @param password 加密解密密码 必须8位字节
- * @param flag 加密解密标志 0:加密 ,1:解密
- * @return
- */
- public static String doWork(String data, String password,int flag) {
- try {
- SecureRandom random = new SecureRandom();
- DESKeySpec desKey = new DESKeySpec(password.getBytes());
- SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
- SecretKey securekey = keyFactory.generateSecret(desKey);
- Cipher cipher = Cipher.getInstance("DES");
- //
- if(flag == 0){
- BASE64Encoder base64encoder = new BASE64Encoder();
- cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
- return base64encoder.encode(cipher.doFinal(data.getBytes("UTF-8")));
- }else{
- BASE64Decoder base64decoder = new BASE64Decoder();
- byte[] encodeByte = base64decoder.decodeBuffer(data);
- cipher.init(Cipher.DECRYPT_MODE, securekey, random);
- byte[] decoder = cipher.doFinal(encodeByte);
- return new String(decoder,"UTF-8");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * test
- * @param args
- */
- public static void main(String[] args) {
- try {
- // 明文
- String str = "mobile:15810557051|type:0|content:你好";
- // 密码
- String password = "01010101";
- String desc = DESHelper.doWork(str, password,0);
- System.out.println("密文:" + desc);
- // 解密
- str = DESHelper.doWork(desc, password,1);
- System.out.println("明文:" +str);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- }
0 0
- RES加密
- res
- res
- res
- res
- PHP RES加密如何避免密文过长和乱码
- RES协议
- Res 协议
- ruby res
- python res
- android res
- android123---res
- DIALOG.RES
- Swift-RES
- android res
- res.location()与res.redirect()
- android中的目录layout、res\anim、res\xml、res\raw,
- res与res-auto的区别
- C++11 in Qt
- Objective-C语法之字面量语法
- Halcon算子--区域特征
- BZOJ3419: Poi2013 Taxis
- 算法4— 判断一个字符串里是否包含另一个字符串所有的字符
- RES加密
- 4.Tornado源码必须要读的几个核心文件----了解Tornado的大致工作机制
- Android中自定义控件的测量及布局
- php笔记(7)——图形图像操作
- 【洛谷P1378】油滴扩展
- schema、dtd、xml之间的关系
- Android DiskLruCache完全解析,硬盘缓存的最佳方案(转)
- 时间管理
- 命令行shell 用于SQLite