本文整理汇总了C#中System.Security.Cryptography.Xml.Reference.LoadXml方法的典型用法代码示例。如果您正苦于以下问题:C# Reference.LoadXml方法的具体用法?C# Reference.LoadXml怎么用?C# Reference.LoadXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.Xml.Reference
的用法示例。
在下文中一共展示了Reference.LoadXml方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KeepDocument
public void KeepDocument ()
{
string result = @"<dsig:Reference URI="""" xmlns:dsig=""http://www.w3.org/2000/09/xmldsig#""><dsig:Transforms><dsig:Transform Algorithm=""http://www.w3.org/2000/09/xmldsig#enveloped-signature"" /></dsig:Transforms><dsig:DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" /><dsig:DigestValue>nDF2V/bzRd0VE3EwShWtsBzTEDc=</dsig:DigestValue></dsig:Reference>";
XmlDocument doc = new XmlDocument ();
doc.LoadXml (xml);
XmlElement org = (XmlElement) doc.SelectSingleNode ("//*[local-name()='Reference']");
Reference r = new Reference ();
r.LoadXml (org);
XmlElement el = r.GetXml ();
Assert.AreEqual (doc, el.OwnerDocument);
Assert.AreEqual (org, el);
Assert.AreEqual (result, el.OuterXml);
}
示例2: VerifySignature
public static bool VerifySignature(Stream xmlStream, Stream signatureStream, out X509Certificate2 certificate)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(signatureStream);
SignedXml signedXml = new SignedXml();
signedXml.LoadXml(xmlDocument.DocumentElement);
certificate = signedXml.KeyInfo.OfType<KeyInfoX509Data>().SelectMany(c => c.Certificates.OfType<X509Certificate2>()).FirstOrDefault();
foreach (Reference reference in signedXml.SignedInfo.References.ToArray())
{
Reference newReference = new Reference(xmlStream);
newReference.LoadXml(reference.GetXml());
signedXml.AddReference(newReference);
signedXml.SignedInfo.References.Remove(reference);
}
return signedXml.CheckSignature();
}
示例3: LoadXml
public void LoadXml(XmlElement value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
XmlElement element = value;
if (!element.LocalName.Equals("SignedInfo"))
{
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo");
}
XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable);
nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
this.m_id = System.Security.Cryptography.Xml.Utils.GetAttribute(element, "Id", "http://www.w3.org/2000/09/xmldsig#");
XmlElement element2 = element.SelectSingleNode("ds:CanonicalizationMethod", nsmgr) as XmlElement;
if (element2 == null)
{
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo/CanonicalizationMethod");
}
this.m_canonicalizationMethod = System.Security.Cryptography.Xml.Utils.GetAttribute(element2, "Algorithm", "http://www.w3.org/2000/09/xmldsig#");
this.m_canonicalizationMethodTransform = null;
if (element2.ChildNodes.Count > 0)
{
this.CanonicalizationMethodObject.LoadInnerXml(element2.ChildNodes);
}
XmlElement element3 = element.SelectSingleNode("ds:SignatureMethod", nsmgr) as XmlElement;
if (element3 == null)
{
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo/SignatureMethod");
}
this.m_signatureMethod = System.Security.Cryptography.Xml.Utils.GetAttribute(element3, "Algorithm", "http://www.w3.org/2000/09/xmldsig#");
XmlElement element4 = element3.SelectSingleNode("ds:HMACOutputLength", nsmgr) as XmlElement;
if (element4 != null)
{
this.m_signatureLength = element4.InnerXml;
}
this.m_references.Clear();
XmlNodeList list = element.SelectNodes("ds:Reference", nsmgr);
if (list != null)
{
foreach (XmlNode node in list)
{
XmlElement element5 = node as XmlElement;
Reference reference = new Reference();
this.AddReference(reference);
reference.LoadXml(element5);
}
}
this.m_cachedXml = element;
}
示例4: LoadXml
public void LoadXml (XmlElement value)
{
if (value == null)
throw new ArgumentNullException ("value");
if ((value.LocalName != XmlSignature.ElementNames.Manifest) || (value.NamespaceURI != XmlSignature.NamespaceURI))
throw new CryptographicException ();
id = GetAttribute (value, XmlSignature.AttributeNames.Id);
for (int i = 0; i < value.ChildNodes.Count; i++) {
XmlNode n = value.ChildNodes [i];
if (n.NodeType == XmlNodeType.Element &&
n.LocalName == XmlSignature.ElementNames.Reference &&
n.NamespaceURI == XmlSignature.NamespaceURI) {
Reference r = new Reference ();
r.LoadXml ((XmlElement) n);
AddReference (r);
}
}
element = value;
}
示例5: LoadXml
public void LoadXml (XmlElement value)
{
if (value == null)
throw new ArgumentNullException ("value");
if ((value.LocalName != XmlSignature.ElementNames.SignedInfo) || (value.NamespaceURI != XmlSignature.NamespaceURI))
throw new CryptographicException ();
id = GetAttribute (value, XmlSignature.AttributeNames.Id);
c14nMethod = XmlSignature.GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.CanonicalizationMethod);
XmlElement sm = XmlSignature.GetChildElement (value, XmlSignature.ElementNames.SignatureMethod, XmlSignature.NamespaceURI);
if (sm != null) {
signatureMethod = sm.GetAttribute (XmlSignature.AttributeNames.Algorithm);
XmlElement length = XmlSignature.GetChildElement (sm, XmlSignature.ElementNames.HMACOutputLength, XmlSignature.NamespaceURI);
if (length != null) {
signatureLength = length.InnerText;
}
}
for (int i = 0; i < value.ChildNodes.Count; i++) {
XmlNode n = value.ChildNodes [i];
if (n.NodeType == XmlNodeType.Element &&
n.LocalName == XmlSignature.ElementNames.Reference &&
n.NamespaceURI == XmlSignature.NamespaceURI) {
Reference r = new Reference ();
r.LoadXml ((XmlElement) n);
AddReference (r);
}
}
element = value;
}
示例6: LoadXml
public void LoadXml(XmlElement value) {
if (value == null)
throw new ArgumentNullException("value");
// SignedInfo
XmlElement signedInfoElement = value;
if (!signedInfoElement.LocalName.Equals("SignedInfo"))
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"), "SignedInfo");
XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);
nsm.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl);
// Id attribute -- optional
m_id = Utils.GetAttribute(signedInfoElement, "Id", SignedXml.XmlDsigNamespaceUrl);
// CanonicalizationMethod -- must be present
XmlElement canonicalizationMethodElement = signedInfoElement.SelectSingleNode("ds:CanonicalizationMethod", nsm) as XmlElement;
if (canonicalizationMethodElement == null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"),"SignedInfo/CanonicalizationMethod");
m_canonicalizationMethod = Utils.GetAttribute(canonicalizationMethodElement, "Algorithm", SignedXml.XmlDsigNamespaceUrl);
m_canonicalizationMethodTransform = null;
if (canonicalizationMethodElement.ChildNodes.Count > 0)
this.CanonicalizationMethodObject.LoadInnerXml(canonicalizationMethodElement.ChildNodes);
// SignatureMethod -- must be present
XmlElement signatureMethodElement = signedInfoElement.SelectSingleNode("ds:SignatureMethod", nsm) as XmlElement;
if (signatureMethodElement == null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_InvalidElement"),"SignedInfo/SignatureMethod");
m_signatureMethod = Utils.GetAttribute(signatureMethodElement, "Algorithm", SignedXml.XmlDsigNamespaceUrl);
// Now get the output length if we are using a MAC algorithm
XmlElement signatureLengthElement = signatureMethodElement.SelectSingleNode("ds:HMACOutputLength", nsm) as XmlElement;
if (signatureLengthElement != null)
m_signatureLength = signatureLengthElement.InnerXml;
// flush out any reference that was there
m_references.Clear();
XmlNodeList referenceNodes = signedInfoElement.SelectNodes("ds:Reference", nsm);
if (referenceNodes != null) {
foreach(XmlNode node in referenceNodes) {
XmlElement referenceElement = node as XmlElement;
Reference reference = new Reference();
AddReference(reference);
reference.LoadXml(referenceElement);
}
}
// Save away the cached value
m_cachedXml = signedInfoElement;
}