Diese Funktion gibt den SHA-1 Hash eines Strings zurück
// using System.Security.Cryptography;
/// <summary>
/// Gets the SHA1 hash.
/// </summary>
/// <param name="text">The text.</param>
/// <returns></returns>
public static string GetSha1Hash(string text)
{
var sha1 = new SHA1CryptoServiceProvider();
string result = null;
var arrayData = Encoding.ASCII.GetBytes(text);
var arrayResult = sha1.ComputeHash(arrayData);
foreach (var t in arrayResult)
{
var temp = Convert.ToString(t, 16);
if (temp.Length == 1)
temp = string.Format("0{0}", temp);
result += temp;
}
return result;
}
Kommentare zum Snippet