本文整理汇总了C#中System.Security.Cryptography.Xml.SignedXml.GetIdElement方法的典型用法代码示例。如果您正苦于以下问题:C# SignedXml.GetIdElement方法的具体用法?C# SignedXml.GetIdElement怎么用?C# SignedXml.GetIdElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.Xml.SignedXml
的用法示例。
在下文中一共展示了SignedXml.GetIdElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIdElement_Null
public void GetIdElement_Null ()
{
SignedXml sign = new SignedXml ();
Assert.IsNull (sign.GetIdElement (null, "value"));
Assert.IsNull (sign.GetIdElement (new XmlDocument (), null));
}
示例2: ValidateSignedInfo
private static void ValidateSignedInfo(SignedXml signedXml, XmlElement xmlElement)
{
if(signedXml.SignedInfo.References.Count == 0)
{
throw new InvalidSignatureException("No reference found in Xml signature, it doesn't validate the Xml data.");
}
if(signedXml.SignedInfo.References.Count != 1)
{
throw new InvalidSignatureException("Multiple references for Xml signatures are not allowed.");
}
var reference = (Reference)signedXml.SignedInfo.References[0];
var id = reference.Uri.Substring(1);
var idElement = signedXml.GetIdElement(xmlElement.OwnerDocument, id);
if(idElement != xmlElement)
{
throw new InvalidSignatureException("Incorrect reference on Xml signature. The reference must be to the root element of the element containing the signature.");
}
foreach (Transform transform in reference.TransformChain)
{
if (!allowedTransforms.Contains(transform.Algorithm))
{
throw new InvalidSignatureException(
"Transform \"" + transform.Algorithm + "\" found in Xml signature SHOULD NOT be used with SAML2.");
}
}
}
示例3: GetIdElement
// adapted from http://bugzilla.ximian.com/show_bug.cgi?id=52084
public void GetIdElement ()
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml (signature);
SignedXml v1 = new SignedXml ();
v1.LoadXml (doc.DocumentElement);
Assert.IsTrue (v1.CheckSignature (), "CheckSignature");
XmlElement xel = v1.GetIdElement (doc, "MyObjectId");
Assert.IsTrue (xel.InnerXml.StartsWith ("<ObjectListTag"), "GetIdElement");
}
示例4: VerifySignature
/// <summary>
/// Verifies the signature.
/// </summary>
/// <param name="xml">The XML.</param>
/// <returns>The issuer certificate</returns>
protected virtual X509Certificate2 VerifySignature(XElement xml)
{
Contract.Requires(xml != null);
Contract.Ensures(Contract.Result<X509Certificate2>() != null);
if ((Configuration == null) || (Configuration.IssuerTokenResolver == null))
{
throw new SecurityTokenException("No issuer token resolver configured");
}
var xmlElement = xml.ToXmlElement();
var signedXml = new SignedXml(xmlElement);
// find signature
XmlNodeList nodeList = xmlElement.GetElementsByTagName("Signature");
// throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// throw an exception if more than one signature was found.
if (nodeList.Count > 1)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// load the <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// resolve the issuer certificate
byte[] thumbprint = Convert.FromBase64String(GetIssuerThumbprint(signedXml));
var identifier = new X509ThumbprintKeyIdentifierClause(thumbprint);
var issuerKey = Configuration.IssuerTokenResolver.ResolveToken(identifier) as X509SecurityToken;
// check the signature
var referenceUri = ((Reference)signedXml.SignedInfo.References[0]).Uri;
if (!signedXml.CheckSignature(issuerKey.Certificate, true)
|| (referenceUri != "" && signedXml.GetIdElement(xmlElement.OwnerDocument, referenceUri) != xmlElement))
{
throw new CryptographicException("Signature verification failed");
}
if (issuerKey.Certificate != null)
{
return issuerKey.Certificate;
}
else
{
throw new CryptographicException("No issuer certificate found");
}
}