Get SHA256 for a string : SHA1Managed « Security « C# / C Sharp






Get SHA256 for a string

 

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace PeDALS.Utilities.Hasher
{
    public static class GenerateHash
    {
        public static string GetSHA256(string path)
        {
            byte[] HashValue, MessageBytes = File.ReadAllBytes(path); 
            SHA256Managed SHhash = new SHA256Managed();
            string strHex = "";

            HashValue = SHhash.ComputeHash(MessageBytes);
            foreach (byte b in HashValue)
            {
                strHex += String.Format("{0:x2}", b);
            }
            return strHex;
        }

    }
}

   
  








Related examples in the same category

1.new SHA1Managed()
2.Encrypt SHA1
3.Encrypt SHA256
4.Returns a SHA1 hash of a given plaintext
5.SHA256 crypt
6.Marshal Str
7.Get SHA1 for a string
8.Get SHA38 for a string
9.Get SHA512 for a string
10.Encrypts a string using the SHA256 algorithm.