请教:一个java中实现的DESede加密算法想翻译成c#版本的 请教:一个java中实现的DESede加密算法想翻译成c#版本的请问这样可以翻译吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下是跟从java版本中找出来的,按照最后一个方法往前推依次找到的相关方法声明:private Cipher cipherEncrypt;方法一: public synchronized byte[] encData(String in) throws MXException { byte temp[] = in.getBytes(); temp = pad(temp); byte encryptVal[] = null; try { encryptVal = cipherEncrypt.doFinal(temp); } catch (Exception e) { e.printStackTrace(); throw new MXSystemException("system", "major", e); } return encryptVal; }方法二: protected byte[] pad(byte in[]) { //经过跟踪padLen = 8 return pad(in, padLen); }方法三: protected byte[] pad(byte in[], int padLen) { if (padLen == 0) return in; int inlen = in.length; int outlen = inlen; int rem = inlen % padLen; if (rem > 0) outlen = inlen + (padLen - rem); byte out[] = new byte[outlen]; for (int xx = 0; xx < inlen; xx++) out[xx] = in[xx]; return out; }方法四:在方法一中的cipherEncrypt定义来源 cipherEncrypt = buildCipher(true);方法五:buildCipher()的定义: Cipher buildCipher(boolean encrypt) throws Exception { Cipher cipher = null; int cryptMode = !encrypt ? 2 : 1; if (secretKey == null || ivSpec == null) { DESedeKeySpec keyspec = new DESedeKeySpec(key.getBytes()); SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm); secretKey = factory.generateSecret(keyspec); ivSpec = new IvParameterSpec(spec.getBytes()); } if (providerClass == null) cipher = Cipher.getInstance(transformation); else cipher = Cipher.getInstance(transformation, providerClass); if (transformation.indexOf("ECB") < 0) cipher.init(cryptMode, secretKey, ivSpec); else cipher.init(cryptMode, secretKey); return cipher; } 基本上是以上几个方法,其他代码太长,这里粘贴出了主要代码,哪位可以指点一下,这个是否够翻译成c#版本的des加密了啊? socket通信问题 SQL SERVER 2005缓存问题 怎样通过服务名获得服务的开启类型? 资源打包问题? 请教如何利用水晶报表打印的问题? trackbar问题 socket在局域网内可以,但一到互联网就出现问题?该如何解决这个问题呢? 求助 (急) 怎么把treeview帮定到dataSet上 在线等! 谢谢 程序整合問題 .Net的使用程度调查,有人在用.Net做项目么? 请教高手:如何为目录(或文件)设置权限 实例化的两个疑问
private Cipher cipherEncrypt;方法一:
public synchronized byte[] encData(String in) throws MXException {
byte temp[] = in.getBytes();
temp = pad(temp);
byte encryptVal[] = null;
try {
encryptVal = cipherEncrypt.doFinal(temp);
} catch (Exception e) {
e.printStackTrace();
throw new MXSystemException("system", "major", e);
}
return encryptVal;
}方法二:
protected byte[] pad(byte in[]) {
//经过跟踪padLen = 8
return pad(in, padLen);
}方法三:
protected byte[] pad(byte in[], int padLen) {
if (padLen == 0)
return in;
int inlen = in.length;
int outlen = inlen;
int rem = inlen % padLen;
if (rem > 0)
outlen = inlen + (padLen - rem);
byte out[] = new byte[outlen];
for (int xx = 0; xx < inlen; xx++)
out[xx] = in[xx]; return out;
}方法四:在方法一中的cipherEncrypt定义来源
cipherEncrypt = buildCipher(true);方法五:buildCipher()的定义:
Cipher buildCipher(boolean encrypt) throws Exception {
Cipher cipher = null;
int cryptMode = !encrypt ? 2 : 1; if (secretKey == null || ivSpec == null) {
DESedeKeySpec keyspec = new DESedeKeySpec(key.getBytes());
SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
secretKey = factory.generateSecret(keyspec);
ivSpec = new IvParameterSpec(spec.getBytes());
}
if (providerClass == null)
cipher = Cipher.getInstance(transformation);
else
cipher = Cipher.getInstance(transformation, providerClass);
if (transformation.indexOf("ECB") < 0)
cipher.init(cryptMode, secretKey, ivSpec);
else
cipher.init(cryptMode, secretKey);
return cipher;
} 基本上是以上几个方法,其他代码太长,这里粘贴出了主要代码,哪位可以指点一下,这个是否够翻译成c#版本的des加密了啊?