Exemple #1
0
        private byte[] CalculateHash(Reference reference, UriResolverDelegate resolver)
        {
            if (reference.Uri == null || reference.Uri.Length == 0 || reference.Uri[0] == '#')
            {
                return((byte[])_calculateHashValue.Invoke(reference, new object[] { _document, null }));
            }

            try
            {
                Stream stream;
                if (resolver != null)
                {
                    stream = resolver(Uri.UnescapeDataString(reference.Uri));
                }
                else
                {
                    using (WebClient wc = new WebClient())
                        stream = wc.OpenRead(reference.Uri);
                }
                return(XadesUtils.CalculateHash(stream, reference.TransformChain, reference.DigestMethod));
            }
            catch (Exception)
            {
                return(new byte[0]);
            }
        }
 /// <summary>
 /// Check signature policy hash
 /// </summary>
 /// <param name="stream"></param>
 /// <returns></returns>`
 public bool CheckPolicyHash(Stream stream)
 {
     byte[] digest = XadesUtils.CalculateHash(stream, PolicyTransformChain, PolicyDigestMethod);
     return(digest.SequenceEqual(PolicyDigest));
 }
 /// <summary>
 /// Update hash value from stream
 /// </summary>
 /// <param name="stream"></param>
 public void CalculatePolicyHash(Stream stream)
 {
     PolicyDigest = XadesUtils.CalculateHash(stream, PolicyTransformChain, PolicyDigestMethod);
 }