Diese Funktion gibt den SHA-1 Hash einer Datei zurück
using System.Security.Cryptography
using System.Text
using Imports System.IO
private string SHA1StringHash(string strString)
{
System.Security.Cryptography.SHA1CryptoServiceProvider SHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] Hash;
string Result = string.Empty;
string Tmp =string.Empty;
FileStream FN = new FileStream(strString, FileMode.Open, FileAccess.Read, FileShare.Read, 8192);
SHA1.ComputeHash(FN);
FN.Close();
Hash = SHA1.Hash;
for (int i = 0; i < Hash.Length; i++)
{
Tmp = Convert.ToString(Hash[i],16);
if (Tmp.Length == 1)
Tmp = "0" + Tmp;
Result += Tmp;
}
return Result;
}
Kommentare zum Snippet