Hashing (also known as hash functions) in cryptography is a process of mapping a binary string of an arbitrary length to a small binary string of a fixed length, known as a hash value, a hash code, or a hash. Hash functions are a common way to protect secure sensitive data such as passwords and digital signatures. Some of the modern commonly-used hash functions are MD5, RIPEMD160, SHA1, SHA256, SHA384, and SHA512.
Hashing is a one-way conversion. You cannot un-hash hashed data.
The NET framework provides cryptography-related functionality encapsulated in System.Security.Cryptography namespace and its classes. The HashAlgorithm class is the base class for hash algorithms including MD5, RIPEMD160, SHA1, SHA256, SHA384, and SHA512.
The ComputeHash method of HashAlgorithm computes a hash. It takes a byte array or stream as an input and returns a hash in the form of a byte array of 256 bits.
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
No matter how big the input data is, the hash will always be 256 bits. The following code snippet is an example of how to create a hash of a string.
using System;
using System.Text;
using System.Security.Cryptography;
namespace HashConsoleApp
{
class Program
{
static void Main(string[] args)
{
string plainData = "Mahesh";
Console.WriteLine("Raw data: {0}", plainData);
string hashedData = ComputeSha256Hash(plainData);
Console.WriteLine("Hash {0}", hashedData);
Console.WriteLine(ComputeSha256Hash("Mahesh"));
Console.ReadLine();
}
static string ComputeSha256Hash(string rawData)
{
// Create a SHA256
using (SHA256 sha256Hash = SHA256.Create())
{
// ComputeHash - returns byte array
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
// Convert byte array to a string
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}
}
}
The output for above code is shown in figure 1.

Figure 1.

Mohammad ImranPosted Aug 6, 2023, 10:36 AM
How to decrypt sha256 with salt? I have encrypted byte array with salt of sha256
Mohammad ImranPosted Aug 6, 2023, 10:35 AM
How to decrypt sha256 with salt?
Mohammad ImranPosted Aug 6, 2023, 10:35 AM
How to decrypt sha256 with salt?
Juan ArielPosted Jan 13, 2022, 9:45 PM
Buenas tardes, en el caso que tuviera que enviar como par?metro un archivo tipo byte[], No tengo claro como construir dicho archivo o que es lo q contiene o c?mo armarlo. Ayuda por favor. public virtual string algoritmoHash(sbyte[] pArchivo, string algorithm)"
Harshad PanchalPosted Dec 1, 2021, 11:46 AM
HELLO, PLEASE HELP ME I WANT RESULT SHA256 encryption should be 32 bytes ONLY.
marvin xuluPosted May 14, 2021, 10:48 AM
Is there a way to undo the hash ?
Gordon FreemanPosted Mar 19, 2019, 2:44 AM
>> No matter how big the input data is, the hash will always be 256 chars. <-- Inaccuracy. It should be 256 bits not chars.
Harsh SinghPosted Nov 1, 2018, 3:23 AM
How can i convert hash password to "Mahesh"
Viknaraj ManogararajahPosted Jul 21, 2018, 11:04 PM
Nice Article, Thank you for sharing