Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 697 Bytes

File metadata and controls

36 lines (29 loc) · 697 Bytes

Cryptography

SHA-256 hasing

private 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();
  }
}

encryption/decryption

There is a service providing cryptographic tools.

public interface ICryptools
{
    string Encrypt(string s);

    string Decrypt(string s);
}