public static Stream GetTransformedStream(string filePath, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM transform) { Stream stream = null; if (transform == System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_MANIFESTINVARIANT) { PEStream stream2 = null; try { stream2 = new PEStream(filePath, true); stream2.ZeroOutOptionalHeaderCheckSum(); stream2.ZeroOutDefaultId1ManifestResource(); return(stream2); } finally { if ((stream2 != stream) && (stream2 != null)) { stream2.Close(); } } } if (transform != System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY) { throw new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_TransformAlgorithmNotSupported"), new object[] { transform.ToString() })); } return(new FileStream(filePath, FileMode.Open, FileAccess.Read)); }
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; }
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); }
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); }