没有时间研究JAVA了,只好求助各位大哥了。以下JAVA写的3DES加密代码,需要用C#重写,最好测试能够通过并且和原JAVA代码的测试结果一致,谢谢了。
public static String EcryptBytes(String s)
throws Exception
{
byte bys[] = s.getBytes("GBK");
String Algorithm = "DESede";
String key = "abcdefghij0123456789klmn";
byte keybyte[] = key.getBytes();
javax.crypto.SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
Cipher cipher = Cipher.getInstance(Algorithm);
cipher.init(1, deskey);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
CipherOutputStream cipherStream = new CipherOutputStream(byteStream, cipher);
GZIPOutputStream gzipStream = new GZIPOutputStream(cipherStream);
gzipStream.write(bys);
gzipStream.close();
StringBuffer sb = new StringBuffer(1200);
byte eBytes[] = byteStream.toByteArray();
int len = eBytes.length / 2;
if(eBytes.length % 2 != 0)
len++;
for(int i = 0; i < len; i++)
{
int data = 0;
if(i * 2 + 1 >= eBytes.length)
data = (0xff & eBytes[i * 2]) + 0x10000;
else
data = (0xff & eBytes[i * 2]) + (0xff & eBytes[i * 2 + 1]) * 256;
String str = (new StringBuilder("00000")).append(String.valueOf(data)).toString();
sb.append(str.substring(str.length() - 5, str.length()));
}
return sb.toString();
}c#java
public static String EcryptBytes(String s)
throws Exception
{
byte bys[] = s.getBytes("GBK");
String Algorithm = "DESede";
String key = "abcdefghij0123456789klmn";
byte keybyte[] = key.getBytes();
javax.crypto.SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
Cipher cipher = Cipher.getInstance(Algorithm);
cipher.init(1, deskey);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
CipherOutputStream cipherStream = new CipherOutputStream(byteStream, cipher);
GZIPOutputStream gzipStream = new GZIPOutputStream(cipherStream);
gzipStream.write(bys);
gzipStream.close();
StringBuffer sb = new StringBuffer(1200);
byte eBytes[] = byteStream.toByteArray();
int len = eBytes.length / 2;
if(eBytes.length % 2 != 0)
len++;
for(int i = 0; i < len; i++)
{
int data = 0;
if(i * 2 + 1 >= eBytes.length)
data = (0xff & eBytes[i * 2]) + 0x10000;
else
data = (0xff & eBytes[i * 2]) + (0xff & eBytes[i * 2 + 1]) * 256;
String str = (new StringBuilder("00000")).append(String.valueOf(data)).toString();
sb.append(str.substring(str.length() - 5, str.length()));
}
return sb.toString();
}c#java
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货