Work with SHA1 in C#

//Generate hash of file public string GetSha1Hash(string filePath) { using (FileStream fs = File.OpenRead(filePath)) { SHA1 sha = new SHA1Managed(); return BitConverter.ToString(sha.ComputeHash(fs)); } } //Generate hash of text public static string TextToHash(string text) { var sh = SHA1.Create(); var hash = new StringBuilder(); byte[] bytes = Encoding.UTF8.GetBytes(text); byte[] b = sh.ComputeHash(bytes); foreach (byte a in b) { var h = a.ToString("x2"); hash.Append(h); } return hash.ToString(); } //complete source on github :https://github.com/mahdiabasi/SHA1Tool
first you must add System.Security.Cryptography name space.
complete source on github : https://github.com/mahdiabasi/SHA1Tool
good luck :)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.