如何将C#加密算法换算成PHP算法(懂C#和PHP大鸟请进)
卫斯理 2011-03-18 02:35:30 [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;
}