public static final String getMd5(String paramString)
{
char[] arrayOfChar1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 };
try
{
byte[] arrayOfByte1 = paramString.getBytes();
MessageDigest localMessageDigest = MessageDigest.getInstance(“MD5”);
localMessageDigest.update(arrayOfByte1);
byte[] arrayOfByte2 = localMessageDigest.digest();
int i = arrayOfByte2.length;
char[] arrayOfChar2 = new char[i * 2];
int j = 0;
int k = 0;
while (true)
{
if (j >= i)
return new String(arrayOfChar2);
int m = arrayOfByte2[j];
int n = k + 1;
arrayOfChar2[k] = arrayOfChar1[(0xF & m >>> 4)];
k = n + 1;
arrayOfChar2[n] = arrayOfChar1[(m & 0xF)];
j++;
}
}
catch (Exception localException)
{
localException.printStackTrace();
}
return null;
}
求大虾把这个代码转换成c#代码,这段代码是反编译APP得到的,他对MD5结果貌似进行了替换位移什么的操作,求代码
{
char[] arrayOfChar1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 };
try
{
byte[] arrayOfByte1 = paramString.getBytes();
MessageDigest localMessageDigest = MessageDigest.getInstance(“MD5”);
localMessageDigest.update(arrayOfByte1);
byte[] arrayOfByte2 = localMessageDigest.digest();
int i = arrayOfByte2.length;
char[] arrayOfChar2 = new char[i * 2];
int j = 0;
int k = 0;
while (true)
{
if (j >= i)
return new String(arrayOfChar2);
int m = arrayOfByte2[j];
int n = k + 1;
arrayOfChar2[k] = arrayOfChar1[(0xF & m >>> 4)];
k = n + 1;
arrayOfChar2[n] = arrayOfChar1[(m & 0xF)];
j++;
}
}
catch (Exception localException)
{
localException.printStackTrace();
}
return null;
}
求大虾把这个代码转换成c#代码,这段代码是反编译APP得到的,他对MD5结果貌似进行了替换位移什么的操作,求代码
解决方案:100分
java转C#,幸好有对应的类,不是所有java程序都能直接对应到C#的!
public static string getMd5(string paramString) //public static final String getMd5(String paramString) { // { // char[] arrayOfChar1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 }; string arrayOfChar1 = "0123456789abcdef"; // try // { // byte[] arrayOfByte1 = paramString.getBytes(); byte[] arrayOfByte1 = Encoding.UTF8.GetBytes(paramString); // MessageDigest localMessageDigest = MessageDigest.getInstance("MD5"); MD5 md5 = new MD5CryptoServiceProvider(); // localMessageDigest.update(arrayOfByte1); // byte[] arrayOfByte2 = localMessageDigest.digest(); byte[] arrayOfByte2 = md5.ComputeHash(arrayOfByte1); // int i = arrayOfByte2.length; int i = arrayOfByte2.Length; // char[] arrayOfChar2 = new char[i * 2]; char[] arrayOfChar2 = new char[i * 2]; // int j = 0; int j = 0; // int k = 0; int k = 0; // while (true) // { while (true) { // if (j >= i) // return new String(arrayOfChar2); if (j >= i) return new string(arrayOfChar2); // int m = arrayOfByte2[j]; int m = arrayOfChar2[j]; // int n = k + 1; int n = k + 1; // arrayOfChar2[k] = arrayOfChar1[(0xF & m >>> 4)]; arrayOfChar2[k] = arrayOfChar1[(m >> 4) & 0x0f]; // k = n + 1; k = n + 1; // arrayOfChar2[n] = arrayOfChar1[(m & 0xF)]; arrayOfChar2[n] = arrayOfChar1[m & 0x0f]; // j++; j++; // } } // } // catch (Exception localException) // { // localException.printStackTrace(); // } // return null; // } }