Exemplo n.º 1
0
        public static Stream GetTransformedStream(string filePath, CMS_HASH_TRANSFORM transform)
        {
            Stream stream = (Stream)null;

            if (transform == CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_MANIFESTINVARIANT)
            {
                PEStream peStream = (PEStream)null;
                try
                {
                    peStream = new PEStream(filePath, true);
                    peStream.ZeroOutOptionalHeaderCheckSum();
                    peStream.ZeroOutDefaultId1ManifestResource();
                    stream = (Stream)peStream;
                    return(stream);
                }
                finally
                {
                    if (peStream != stream && peStream != null)
                    {
                        peStream.Close();
                    }
                }
            }
            else
            {
                if (transform == CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY)
                {
                    return((Stream) new FileStream(filePath, FileMode.Open, FileAccess.Read));
                }
                throw new NotSupportedException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_TransformAlgorithmNotSupported"), new object[1]
                {
                    (object)transform.ToString()
                }));
            }
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
        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();
                }
            }
        }
Exemplo n.º 4
0
 public void AddHash(byte[] digestValue, CMS_HASH_DIGESTMETHOD digestMethod, CMS_HASH_TRANSFORM transform)
 {
     this._hashes.Add((object)new Hash(digestValue, digestMethod, transform));
 }