using System.Security.Cryptography;
public static string EncryptPassword(string password)
UnicodeEncoding UE = new UnicodeEncoding();
byte[] message = UE.GetBytes(password);
SHA256Managed hashString = new SHA256Managed();
hashValue = hashString.ComputeHash(message);
Console.WriteLine(hashValue);
foreach (byte x in hashValue)
hex += String.Format("{0:x2}", x);
static string ComputeSha256Hash(string rawData)
using (SHA256 sha256Hash = SHA256.Create())
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
builder.Append(bytes[i].ToString("x2"));
return builder.ToString();
public static void Main()
string enc = EncryptPassword("p@ssw0rd");
string enc1 = ComputeSha256Hash("p@ssw0rd");