Get Sha1 Hash - CSharp Security

CSharp examples for Security:Hash

Description

Get Sha1 Hash

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.IO;/*from   w w  w. j a  v  a 2 s.c om*/
using System;

public class Main{
        public static string GetSha1Hash(this string value)
        {
            if (string.IsNullOrEmpty(value))
                throw new ArgumentException("String is empty and not hashable.");
            var ascii = Encoding.ASCII.GetBytes(value);
            var bytes = SHA1.Create().ComputeHash(ascii);
            return bytes.Aggregate("", (current, b) => current + String.Format("{0:x2}", b));
        }
}

Related Tutorials