public static HashAlgorithm GetHashAlgorithm(CMS_HASH_DIGESTMETHOD digestMethod) { if (digestMethod == CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA1) { return((HashAlgorithm) new SHA1CryptoServiceProvider()); } if (digestMethod == CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA256) { if (PlatformSpecific.OnWindows2003 || PlatformSpecific.OnVistaOrAbove) { return(CryptoConfig.CreateFromName("System.Security.Cryptography.SHA256CryptoServiceProvider") as HashAlgorithm); } return((HashAlgorithm) new SHA256Managed()); } if (digestMethod == CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA384) { if (PlatformSpecific.OnWindows2003 || PlatformSpecific.OnVistaOrAbove) { return(CryptoConfig.CreateFromName("System.Security.Cryptography.SHA384CryptoServiceProvider") as HashAlgorithm); } return((HashAlgorithm) new SHA384Managed()); } if (digestMethod == CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA512) { if (PlatformSpecific.OnWindows2003 || PlatformSpecific.OnVistaOrAbove) { return(CryptoConfig.CreateFromName("System.Security.Cryptography.SHA512CryptoServiceProvider") as HashAlgorithm); } return((HashAlgorithm) new SHA512Managed()); } throw new NotSupportedException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_DigestMethodNotSupported"), new object[1] { (object)digestMethod.ToString() })); }
public Hash(byte[] digestValue, CMS_HASH_DIGESTMETHOD digestMethod, CMS_HASH_TRANSFORM transform) { if (digestValue == null) { throw new ArgumentException(Resources.GetString("Ex_HashNullDigestValue")); } this._digestValue = digestValue; this._digestMethod = digestMethod; this._transform = transform; }
public static byte[] GenerateDigestValue(string filePath, CMS_HASH_DIGESTMETHOD digestMethod, CMS_HASH_TRANSFORM transform) { Stream inputStream = (Stream)null; try { HashAlgorithm hashAlgorithm = ComponentVerifier.GetHashAlgorithm(digestMethod); inputStream = ComponentVerifier.GetTransformedStream(filePath, transform); return(hashAlgorithm.ComputeHash(inputStream)); } finally { if (inputStream != null) { inputStream.Close(); } } }
public void AddHash(byte[] digestValue, CMS_HASH_DIGESTMETHOD digestMethod, CMS_HASH_TRANSFORM transform) { this._hashes.Add((object)new Hash(digestValue, digestMethod, transform)); }