以下是跟从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加密了啊?
没分了 不好意思 请大家帮忙看看吧
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加密了啊?
没分了 不好意思 请大家帮忙看看吧
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货