public GetSignatureKeys ( ) : System.Security.Cryptography.Xml.KeyInfo | ||
리턴 | System.Security.Cryptography.Xml.KeyInfo |
public void AddAttribute_01() { Saml20Assertion assertion = LoadAssertion(@"Saml20\Assertions\Saml2Assertion_01"); List<SamlAttribute> attributes = assertion.Attributes; attributes.Add(DKSaml20PostalAddressAttribute.Create("DK-2200 København")); X509Certificate2 cert = AssertionUtil.GetCertificate1(); assertion.Sign(cert); assertion.CheckValid(new AsymmetricAlgorithm[] { cert.PublicKey.Key }); // Verify that the modified assertion can survive complete serialization and deserialization. string assertionString = assertion.GetXml().OuterXml; XmlDocument deserializedAssertionDoc = new XmlDocument(); deserializedAssertionDoc.PreserveWhitespace = true; deserializedAssertionDoc.Load(new StringReader(assertionString)); Saml20Assertion deserializedAssertion = new Saml20Assertion(deserializedAssertionDoc.DocumentElement, null, false); Assert.IsNotNull(deserializedAssertion.GetSignatureKeys(), "Signing keys must be present"); deserializedAssertion.CheckValid(new AsymmetricAlgorithm[] { cert.PublicKey.Key }); }
/// <summary> /// Loads an assertion, deserializes it using the <code>Assertion</code> class and returns the /// resulting <code>Assertion</code> instance. /// </summary> public static Saml20Assertion DeserializeToken(string assertionFile) { FileStream fs = File.OpenRead(assertionFile); XmlDocument document = new XmlDocument(); document.PreserveWhitespace = true; document.Load(fs); fs.Close(); Saml20Assertion assertion = new Saml20Assertion(document.DocumentElement, null, false); List<AsymmetricAlgorithm> result = new List<AsymmetricAlgorithm>(1); foreach (KeyInfoClause clause in assertion.GetSignatureKeys()) { AsymmetricAlgorithm key = XmlSignatureUtils.ExtractKey(clause); result.Add(key); } assertion.CheckValid(result); return assertion; }