码迷,mamicode.com
首页 > 其他好文 > 详细

DES解密

时间:2020-01-19 19:33:16      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:encrypt   odi   spec   data   parameter   byte   obj   sig   imp   

import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import sun.misc.BASE64Decoder;
String key ="你自己的desKEY";//引用key
String body=prev.getResponseDataAsString();
import org.json.JSONObject; //导入
import org.json.*;
prev.setDataEncoding("utf-8");
// 加密方法
public String DecryptAsDoNet(String message) {
    try {
    	   byte[] encrypted1 = new BASE64Decoder().decodeBuffer(message);
        Base64.Encoder encoder = Base64.getEncoder();
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
        IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
        cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
        byte[] encryptbyte = cipher.doFinal(encrypted1);
        String str =new String(encryptbyte,"utf-8");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 			     
        return str;
        }
    catch (Throwable e) {
        e.printStackTrace();
        return "";
    }
}	
    
 // 解密
String decrypt = DecryptAsDoNet(body);
vars.put("DESSign",decrypt);
JSONObject resbonseJson = new JSONObject(decrypt); //解析json
String code = resbonseJson.get("code").toString();
String Token = resbonseJson.get("data").get("accessToken").toString();
log.info("请求登录返回报文"+decrypt);
vars.put("DESSign",decrypt);
vars.put("rescode",code);
log.info("登录接口响应code"+code);
vars.put("Token",Token);
log.info("登录token:" + Token)

DES解密

标签:encrypt   odi   spec   data   parameter   byte   obj   sig   imp   

原文地址:https://www.cnblogs.com/yaobiluo/p/12215046.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!