用 Java 解密 C# 加密的数据(DES)
用 Java 解密 C# 加密的数据(DES)
[原文地址:http://yidinghe.cnblogs.com/articles/449212.html]
今天碰上一件令我头大的事情。我们的系统要和一个外部系统进行通讯,传输方式是采用 DES 算法对消息进行加密,再用 BASE64 编码。不过对方系统是用 C# 写的。平台不一样,于是我和对面的老兄先测试一下加密解密。这一测试问题就来了。两边采用同样的密钥,对同一个字符串加密出来的结果不一样。怎么办呢?我先把他那边的代码要过来了,他是这样写的(C#):
public static string Encrypt(string message, string key)
{
DES des = new DESCryptoServiceProvider();
des.Key = Encoding.UTF8.GetBytes(key);
des.IV = Encoding.UTF8.GetBytes(key);
byte[] bytes = Encoding.UTF8.GetBytes(message);
byte[] resultBytes = des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
return Convert.ToBase64String(resultBytes);
}
而我这边呢,是用 Java 这样写的(仅仅加密到字节串,BASE64 编码是在另一个类里):
public static byte[] desEncrypt(String message, String key) throws Exception {
Cipher cipher = Cipher.getInstance("DES");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret
相关文档:
JAVA是一种平台,也是一种程序设计语言,如何学好程序设计不仅仅适用于JAVA,对C++等其他程序设计语言也一样管用。有编程高手认为,JAVA也好C也好没什么分别,拿来就用。为什么他们能达到如此境界?我想是因为编程语言之间有共通之处,领会了编程的精髓,自然能够做到一通百通。如何学习程序设计理所当然也有许多共通的地方 ......
【摘要
JAVA语言是目前Internet上大型的WEB应用程序开发时使用得最热门的编程语言,本文描述了JAVA和JSP技术的特征以及在互联网上的使用情况,介绍这两种技术的重要编程方法和两者之关的联系,并完成一个基于这种技术的网上书店系统。
【关键字JAVA, JavaBeans, Servlet, JSP, 网络编程, 电子商务, 网上书店
Abstract
A ......
/*****************Animal.java begin ***********************/
public class Animal{
public void jj(){
}
public static void main(String args[]){
//编译时类型 //运行时类型
Animal anima ......
1.基本概念的理解
绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:
C:xyz est.txt 代表了test.txt文件的绝对路径。http://www.sun.com/index.htm也代表了一个URL绝对路径。
相对路径:相对与某个基准目录的路径。包含Web的相对路径(HTML中的相对目录),例如:在
Servl ......
If the requested address is not a valid virtual memory address (it doesn't belong to any of
the memory segments of the executing process), the page cannot be validated, and
a segmentation fault is generated. This vectors control to another part of the kernel and
usually results in the pro ......