求 DESede 的解密方法。

2015-09-23 09:34:30 +08:00
 qq459969411
这个貌似 pp 没有县城的函数,有大神有这方面的代码吗?
2638 次点击
所在节点    PHP
1 条回复
jiaqidianbo
2015-09-23 09:38:43 +08:00
/**
* 解密算法
* cryptograph:密文
*/
public static String decrypt(String cryptograph) throws Exception{
/** 将文件中的私钥对象读出 */
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(PRIVATE_KEY_FILE));
Key key = (Key) ois.readObject();
/** 得到 Cipher 对象对已用公钥加密的数据进行 RSA 解密 */
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
BASE64Decoder decoder = new BASE64Decoder();
byte[] b1 = decoder.decodeBuffer(cryptograph);
/** 执行解密操作 */
byte[] b = cipher.doFinal(b1);
return new String(b);
}
public static void main(String[] args) throws Exception {
String source = "火车";//要加密的字符串
System.out.println("要加密的字符串:"+source);
String cryptograph = encrypt(source);//生成的密文
System.out.println("生成的密文:"+cryptograph+"==================");

String target = decrypt(cryptograph);//解密密文
System.out.println("解密密文:"+target+"------------------------");
}
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/222970

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX