public class SHAHelper { public static string HashStringSHA2(params string[] inputString) { string val = inputString.Aggregate("", (current, s) => current + s); return HashString(val, "SHA256"); } public static string HashString(string inputString, string hashName) { HashAlgorithm algorithm = HashAlgorithm.Create(hashName); if (algorithm == null) { throw new ArgumentException("Unrecognized hash name", "hashName"); } byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString)); return Convert.ToBase64String(hash); } public static bool IsSameSHA2(string hashCode, params string[] inputString) { if (string.IsNullOrWhiteSpace(hashCode)) { return false; } return hashCode.Equals(HashStringSHA2(inputString), StringComparison.OrdinalIgnoreCase); } }