コード例 #1
0
 public static HashAlgorithm GetHashAlgorithm(System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD digestMethod)
 {
     if (digestMethod == System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA1)
     {
         return(new SHA1CryptoServiceProvider());
     }
     if (digestMethod == System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA256)
     {
         if (PlatformSpecific.OnWindows2003 || PlatformSpecific.OnVistaOrAbove)
         {
             return(CryptoConfig.CreateFromName("System.Security.Cryptography.SHA256CryptoServiceProvider") as HashAlgorithm);
         }
         return(new SHA256Managed());
     }
     if (digestMethod == System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA384)
     {
         if (PlatformSpecific.OnWindows2003 || PlatformSpecific.OnVistaOrAbove)
         {
             return(CryptoConfig.CreateFromName("System.Security.Cryptography.SHA384CryptoServiceProvider") as HashAlgorithm);
         }
         return(new SHA384Managed());
     }
     if (digestMethod != System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA512)
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_DigestMethodNotSupported"), new object[] { digestMethod.ToString() }));
     }
     if (!PlatformSpecific.OnWindows2003 && !PlatformSpecific.OnVistaOrAbove)
     {
         return(new SHA512Managed());
     }
     return(CryptoConfig.CreateFromName("System.Security.Cryptography.SHA512CryptoServiceProvider") as HashAlgorithm);
 }
コード例 #2
0
 public Hash(byte[] digestValue, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD digestMethod, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform)
 {
     if (digestValue == null)
     {
         throw new ArgumentException(Resources.GetString("Ex_HashNullDigestValue"));
     }
     this._digestValue = digestValue;
     this._digestMethod = digestMethod;
     this._transform = transform;
 }
コード例 #3
0
 public Hash(byte[] digestValue, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD digestMethod, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform)
 {
     if (digestValue == null)
     {
         throw new ArgumentException(Resources.GetString("Ex_HashNullDigestValue"));
     }
     this._digestValue  = digestValue;
     this._digestMethod = digestMethod;
     this._transform    = transform;
 }
コード例 #4
0
        public static byte[] GenerateDigestValue(string filePath, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD digestMethod, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform)
        {
            Stream inputStream = null;

            byte[] buffer = null;
            try
            {
                HashAlgorithm hashAlgorithm = GetHashAlgorithm(digestMethod);
                inputStream = GetTransformedStream(filePath, transform);
                buffer      = hashAlgorithm.ComputeHash(inputStream);
            }
            finally
            {
                if (inputStream != null)
                {
                    inputStream.Close();
                }
            }
            return(buffer);
        }
コード例 #5
0
        public void AddHash(byte[] digestValue, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD digestMethod, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform)
        {
            Hash hash = new Hash(digestValue, digestMethod, transform);

            this._hashes.Add(hash);
        }