[C#]
public static string CreateServerPasswordFromOriginalPassword(string source)
{
byte[] byteA = stringToBytes(source);
string result = md5(byteA);
byte[] byteB = new byte[result.Length / 2];
for (int i = 0; i < result.Length / 2; i++)
{
byteB[i] = (byte)Convert.ToInt32(result.Substring(i * 2, 2), 16);
} return md5(byteB); } public static String md5(byte[] srcBytes)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytes = srcBytes;
bytes = md5.ComputeHash(bytes);
md5.Clear(); string ret = "";
for (int i = 0; i < bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
} return ret.PadLeft(32, '0');
} public static byte[] stringToBytes(string src)
{
char[] szChar = src.ToCharArray();
byte[] szByte = new byte[szChar.Length];
for (int i = 0; i < szChar.Length; i++)
{
szByte[i] = (byte)szChar[i];
}
return szByte;
}
public static string CreateServerPasswordFromOriginalPassword(string source)
{
byte[] byteA = stringToBytes(source);
string result = md5(byteA);
byte[] byteB = new byte[result.Length / 2];
for (int i = 0; i < result.Length / 2; i++)
{
byteB[i] = (byte)Convert.ToInt32(result.Substring(i * 2, 2), 16);
} return md5(byteB); } public static String md5(byte[] srcBytes)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytes = srcBytes;
bytes = md5.ComputeHash(bytes);
md5.Clear(); string ret = "";
for (int i = 0; i < bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
} return ret.PadLeft(32, '0');
} public static byte[] stringToBytes(string src)
{
char[] szChar = src.ToCharArray();
byte[] szByte = new byte[szChar.Length];
for (int i = 0; i < szChar.Length; i++)
{
szByte[i] = (byte)szChar[i];
}
return szByte;
}
但是我想要的效果是和NET源码跑出了的值一样。
PHP的MD5和C#的MD5 肯定一样