private byte[] GetC14NDigest(HashAlgorithm hash) { if (!_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); _digestedSignedInfo = c14nMethodTransform.GetDigestedOutput(hash); _bCacheValid = true; } return(_digestedSignedInfo); }
// // private methods // private byte[] GetC14NDigest(HashAlgorithm hash) { bool isKeyedHashAlgorithm = hash is KeyedHashAlgorithm; string baseUri = _containingDocument?.BaseURI; XmlDocument doc = Utils.PreProcessElementInput(m_signature.GetXml()); // Add non default namespaces in scope CanonicalXmlNodeList namespaces = (_context == null ? null : Utils.GetPropagatedAttributes(_context)); Utils.AddNamespaces(doc.DocumentElement, namespaces); Transform c14nMethodTransform = m_signature.CanonicalizationMethodObject; c14nMethodTransform.LoadInput(doc); return(c14nMethodTransform.GetDigestedOutput(hash)); }
private byte[] GetC14NDigest(HashAlgorithm hash) { if (!this.bCacheValid || !this.SignedInfo.CacheValid) { string securityUrl = (this.m_containingDocument == null) ? null : this.m_containingDocument.BaseURI; XmlResolver xmlResolver = this.m_bResolverSet ? this.m_xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), securityUrl); XmlDocument document = System.Security.Cryptography.Xml.Utils.PreProcessElementInput(this.SignedInfo.GetXml(), xmlResolver, securityUrl); CanonicalXmlNodeList namespaces = (this.m_context == null) ? null : System.Security.Cryptography.Xml.Utils.GetPropagatedAttributes(this.m_context); SignedXmlDebugLog.LogNamespacePropagation(this, namespaces); System.Security.Cryptography.Xml.Utils.AddNamespaces(document.DocumentElement, namespaces); Transform canonicalizationMethodObject = this.SignedInfo.CanonicalizationMethodObject; canonicalizationMethodObject.Resolver = xmlResolver; canonicalizationMethodObject.BaseURI = securityUrl; SignedXmlDebugLog.LogBeginCanonicalization(this, canonicalizationMethodObject); canonicalizationMethodObject.LoadInput(document); SignedXmlDebugLog.LogCanonicalizedOutput(this, canonicalizationMethodObject); this._digestedSignedInfo = canonicalizationMethodObject.GetDigestedOutput(hash); this.bCacheValid = true; } return(this._digestedSignedInfo); }