[英]C# hashing algorithm MD5(Sha1(pass))
所以基本上我得到了這個算法:
MD5(SHA1(PASSWORD));
我正在嘗試用C#計算它,但是我沒有運氣。 這是我當前的代碼:
string pass = txtPass.Text;
string sha1 = GetSha1(pass);
string md5 = CalculateMD5Hash(sha1);
textBox1.Text = md5;
但是,它不會輸出正確的數據,我知道這是正確的。
例如,如果我要將“ stackoverflow”轉換為sha1,我將得到:fdfeb16f096983ada02db49d46a8154475d700ae
那么如果我對md5說sha1我會得到:341fe8f2ac67f95f20d2d0b721d53847
但是,如果我讓我的C#腳本執行此操作,則會得到以下信息:381678D7800D83D014DB3DF1B704FE23
這里有些事情沒有意義,我不確定這是什么。
MD5(SHA1("stackoverflow")); //341fe8f2ac67f95f20d2d0b721d53847
public String MD5(String input)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
Byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
Byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
public String SHA1(String s)
{
Byte[] bytes = Encoding.UTF8.GetBytes(s);
var sha1 = System.Security.Cryptography.SHA1.Create();
Byte[] hashBytes = sha1.ComputeHash(bytes);
return HexStringFromBytes(hashBytes);
}
public String HexStringFromBytes(Byte[] bytes)
{
var sb = new StringBuilder();
foreach(byte b in bytes)
{
var hex = b.ToString("x2");
sb.Append(hex);
}
return sb.ToString();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.