shivakb
6/12/2018 - 6:10 AM

Encrypt strings in c# with sha256

To get the encrypted string by given string

//SHA-256
public static string sha256(string randomString){
    var crypt = new System.Security.Cryptography.SHA256Managed();
    var hash = new System.Text.StringBuilder();
    byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(randomString));
    
    foreach (byte theByte in crypto){
        hash.Append(theByte.ToString("x2"));
    }
    return hash.ToString();
}