public static string CalculateShaHash(NameValueCollection parameters, OgoneHashAlgorithm hashAlgorithm, string passPhrase) { var dict = parameters.AllKeys.ToDictionary(k => k.ToUpper(), k => parameters[k]); var sortedDict = new SortedDictionary <string, string>(dict); var stringForHashing = string.Empty; sortedDict.Where(p => !string.IsNullOrWhiteSpace(p.Value)) .ToList() .ForEach(p => { stringForHashing += string.Concat(p.Key, "=", p.Value, passPhrase); }); var encoding = Encoding.UTF8; var bytesToHash = encoding.GetBytes(stringForHashing); using (var sha = GetHashAlgorithm(hashAlgorithm)) { var hash = sha.ComputeHash(bytesToHash); var hashString = BitConverter.ToString(hash); hashString = hashString.Replace("-", string.Empty); return(hashString); } }
private static HashAlgorithm GetHashAlgorithm(OgoneHashAlgorithm hashAlgorithm) { switch (hashAlgorithm) { case OgoneHashAlgorithm.Sha1: return(new SHA1Managed()); case OgoneHashAlgorithm.Sha256: return(new SHA256Managed()); case OgoneHashAlgorithm.Sha512: return(new SHA512Managed()); default: return(null); } }