我对此有点抓狂了!我正在尝试根据现有的数据库对我的应用程序进行身份验证(所以我不能更改PHP端),我需要将我的密码字段转换为与php的md5(moo)命令相同的密码字段。
然而,我尝试创建散列的每个公式都具有相同的md5,与数据库中的内容非常不同。
有没有一个公式可以产生同样的结果?
我试过了:
public static string MbelcherEncodePassword(string originalPassword)
{
Byte[] originalBytes;
Byte[] encodedBytes;
MD5 md5;
// Conver the original password to bytes; then create the hash
md5 = new MD5CryptoServiceProvider();
originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
encodedBytes = md5.ComputeHash(originalBytes);
// Bytes to string
return System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
}
和:
public static string MD5(string password)
{
byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
try
{
System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash = cryptHandler.ComputeHash(textBytes);
string ret = "";
foreach (byte a in hash)
{
if (a < 16)
ret += "0" + a.ToString("x");
else
ret += a.ToString("x");
}
return ret;
}
catch
{
throw;
}
}
和:
public static string MD5Hash(string text)
{
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
return System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.Default.GetBytes(text))), "-", "");
}
无济于事。任何帮助都将不胜感激!
谢谢
发布于 2013-06-27 22:09:56
下面应该会给出与PHP md5相同的十六进制字符串:
public string GetMd5Hex(MD5 crypt, string input)
{
return crypt.ComputeHash(UTF8Encoding.UTF8.GetBytes(input))
.Select<byte, string>(a => a.ToString("x2"))
.Aggregate<string>((a, b) => string.Format("{0}{1}", a, b));
}
https://stackoverflow.com/questions/17344151
复制相似问题