Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool Verify(X509Certificate2 cert, XmlElement xmlElement, SignedXml signedXml)
- {
- bool flag;
- try
- {
- KeyInfo keyInfo = new KeyInfo();
- var clause = new KeyInfoX509Data(cert);
- keyInfo.AddClause(clause);
- XmlElement signatureElement = GetSignatureElement(xmlElement);
- if (signatureElement == null)
- {
- string message = "The XML does not contain a signature.";
- throw new SAMLSignatureException(message);
- }
- signedXml.LoadXml(signatureElement);
- if (keyInfo != null)
- {
- signedXml.KeyInfo = keyInfo;
- }
- SetSigningKeyFromKeyInfo(signedXml);
- flag = signedXml.CheckSignature(cert.PublicKey.Key);
- }
- catch (Exception exception)
- {
- throw new SAMLSignatureException("Failed to verify the XML signature.", exception);
- }
- return flag;
- }
- private static void SetSigningKeyFromKeyInfo(SignedXml signedXml)
- {
- IEnumerator enumerator = signedXml.KeyInfo.GetEnumerator();
- while (enumerator.MoveNext())
- {
- if (enumerator.Current is KeyInfoX509Data)
- {
- var current = (KeyInfoX509Data) enumerator.Current;
- if (current.Certificates.Count != 0)
- {
- var certificate = (X509Certificate) current.Certificates[0];
- var certificate2 = new X509Certificate2(certificate);
- AsymmetricAlgorithm key = certificate2.PublicKey.Key;
- signedXml.SigningKey = key;
- return;
- }
- }
- else
- {
- if (enumerator.Current is RSAKeyValue)
- {
- var value2 = (RSAKeyValue) enumerator.Current;
- signedXml.SigningKey = value2.Key;
- return;
- }
- if (enumerator.Current is DSAKeyValue)
- {
- var value3 = (DSAKeyValue) enumerator.Current;
- signedXml.SigningKey = value3.Key;
- return;
- }
- }
- }
- throw new SAMLSignatureException("No signing key could be found in the key info.");
- }
- var saml = System.Text.Encoding.Default.GetString(Convert.FromBase64String(samlToken))
- var saml = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(samlToken))
Add Comment
Please, Sign In to add comment