私はこれで少し夢中になります!既存のデータベースに対してアプリを認証しようとしています (そのため、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))), "-", "");
}
無駄に。どんな助けでも本当に感謝します!
ありがとう