コード例 #1
0
        public static void GetC14NDigest(IHash hash, SignedXml signedXml)
        {
            bool isKeyedHashAlgorithm = hash is MacHashWrapper;

            if (isKeyedHashAlgorithm || !signedXml.IsCacheValid || !signedXml.SignedInfo.CacheValid)
            {
                string      baseUri  = (signedXml.ContainingDocument == null ? null : signedXml.ContainingDocument.BaseURI);
                XmlResolver resolver = (signedXml._bResolverSet ? signedXml._xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), baseUri));
                XmlDocument doc      = StreamUtils.PreProcessElementInput(signedXml.SignedInfo.GetXml(), resolver, baseUri);

                CanonicalXmlNodeList namespaces = (signedXml._context == null ? null : ElementUtils.GetPropagatedAttributes(signedXml._context));
                SignedXmlDebugLog.LogNamespacePropagation(signedXml, namespaces);
                ElementUtils.AddNamespaces(doc.DocumentElement, namespaces);

                Transform c14nMethodTransform = signedXml.SignedInfo.CanonicalizationMethodObject;
                c14nMethodTransform.Resolver = resolver;
                c14nMethodTransform.BaseURI  = baseUri;

                SignedXmlDebugLog.LogBeginCanonicalization(signedXml, c14nMethodTransform);
                c14nMethodTransform.LoadInput(doc);
                SignedXmlDebugLog.LogCanonicalizedOutput(signedXml, c14nMethodTransform);
                c14nMethodTransform.GetDigestedOutput(hash);

                signedXml.IsCacheValid = !isKeyedHashAlgorithm;
            }
        }
        private void GetC14NDigest(IHash hash)
        {
            bool isKeyedHashAlgorithm = hash is MacHashWrapper;

            if (isKeyedHashAlgorithm || !_bCacheValid || !SignedInfo.CacheValid)
            {
                string      baseUri  = (_containingDocument == null ? null : _containingDocument.BaseURI);
                XmlResolver resolver = (_bResolverSet ? _xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), baseUri));
                XmlDocument doc      = Utils.PreProcessElementInput(SignedInfo.GetXml(), resolver, baseUri);

                // Add non default namespaces in scope
                CanonicalXmlNodeList namespaces = (_context == null ? null : Utils.GetPropagatedAttributes(_context));
                SignedXmlDebugLog.LogNamespacePropagation(this, namespaces);
                Utils.AddNamespaces(doc.DocumentElement, namespaces);

                Transform c14nMethodTransform = SignedInfo.CanonicalizationMethodObject;
                c14nMethodTransform.Resolver = resolver;
                c14nMethodTransform.BaseURI  = baseUri;

                SignedXmlDebugLog.LogBeginCanonicalization(this, c14nMethodTransform);
                c14nMethodTransform.LoadInput(doc);
                SignedXmlDebugLog.LogCanonicalizedOutput(this, c14nMethodTransform);
                c14nMethodTransform.GetDigestedOutput(hash);

                _bCacheValid = !isKeyedHashAlgorithm;
            }
        }