【发布时间】:2011-03-11 05:06:31
【问题描述】:
我在 C# 中有一个哈希算法,简而言之,它是:
string hashCode = string.Empty;
if (null != password)
{
System.Security.Cryptography.MD5 cryptography = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] code = cryptography.ComputeHash(Encoding.Default.GetBytes(password));
StringBuilder stringBuilder = new StringBuilder();
// Converting the code to string.
for (int i = 0; i < code.Length; i++)
{
stringBuilder.Append(code[i].ToString("x2"));
}
hashCode = stringBuilder.ToString();
}
return hashCode;
}
现在我需要在 php 中复制这种行为..... 在此先感谢...
注意:我无法更改 C# 行为,因为它已经实现并且密码已使用此算法保存在我的数据库中。
【问题讨论】:
-
您的问题是什么?您希望我们为您编写代码吗?或者你想要一些指针?另外,使用 SHA 而不是 MD5 进行加密。
-
伙计们,拜托,MD5 不是加密。
-
PHP 通过一个简单的 md5("your string here") 函数开箱即用地做到了这一点