Calculate SHA1 hash from given string - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:SHA1

Description

Calculate SHA1 hash from given string

Demo Code


using System.Text;
using System.Security.Cryptography;
using System;// w w  w . j ava  2  s . c o m

public class Main{
        /// <summary>
        /// Calculate SHA1 hash from given string
        /// </summary>
        public static byte[] CalculateSha1Hash(string val)
        {
            byte[] data = Encoding.UTF8.GetBytes(val);
            SHA1 sha = new SHA1Managed();
            return sha.ComputeHash(data);
        }
}

Related Tutorials