|
楼主 |
发表于 2014-12-9 16:39:27
|
显示全部楼层
byte[] str = new byte[pToDecrypt.Length / 2];
for (int x = 0; x < pToDecrypt.Length / 2; x++)
{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
str[x] = (byte)i;
}
byte[] key = ASCIIEncoding.ASCII.GetBytes(pkey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Padding = PaddingMode.None;
Type t = Type.GetType("System.Security.Cryptography.CryptoAPITransformMode");
object obj = t.GetField("Decrypt", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).GetValue(t);
MethodInfo mi = des.GetType().GetMethod("_NewEncryptor", BindingFlags.Instance | BindingFlags.NonPublic);
ICryptoTransform desCrypt = (ICryptoTransform)mi.Invoke(des, new object[] { key, CipherMode.ECB, null, 0, obj });
byte[] result = desCrypt.TransformFinalBlock(str, 0, str.Length);
return BitConverter.ToString(result).Replace("-", ""); |
|