Wie um zu Überprüfen, die eine RSA-SHA512 XML-Signatur in .NET?

Mit Hilfe der MSDN-Website über SignedXml, kann ich leicht überprüfen, ob eine XML-DSig ist richtig. Es funktioniert perfekt, wenn die Signatur-Methode sha1 verwendet wurde.

Jedoch, wenn ich die SignatureMethod RSA-SHA512 (http://www.w3.org/2001/04/xmldsig-more#rsa-sha512), CheckSignature() bricht mit einer CryptograhicException: SignatureDescription konnte nicht erstellt werden für den Algorithmus der Signatur geliefert.

Wie es scheint, CheckSignature() ist nicht in der Lage, um zu überprüfen, RSA-SHA512-Signaturen.

Weiß jemand, wie man überprüfen diese Art von Signaturen?

Den code aus der MSDN-Website, ist:

public static bool VerifyXml(XmlDocument doc, bool removeSignatureElement = false)
{
    //Check arguments.
    if (doc == null)
        throw new ArgumentException("doc");

    //Create a new SignedXml object and pass it the XML document class.
    SignedXml signedXml = new SignedXml(doc);

    //Find the "Signature" node and create a new XmlNodeList object.
    XmlNodeList nodeList = doc.GetElementsByTagName("Signature", Constants.NamespaceDSig);

    //Throw an exception if no signature was found.
    if (nodeList.Count < 1)
    {
        throw new CryptographicException("Verification failed: No Signature was found in the document.");
    }

    //This example only supports one signature for the entire XML 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 first <signature> node.  
    signedXml.LoadXml((XmlElement)nodeList[0]);

    //Check the signature and return the result.
    bool signedCorrectly = signedXml.CheckSignature(); //throws the Exception!!!

    return signedCorrectly;
}

Den signierten XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Notification xmlns="http://www.xxxxxxxxxxx.xx/xxxxx">
    <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Content"> ... </xenc:EncryptedData>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:SignedInfo>
            <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
            <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"/>
            <ds:Reference URI="">
                <ds:Transforms>
                    <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                    <ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
                </ds:Transforms>
                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                <ds:DigestValue>WsHcyNL7Jh8HSzR9ArzTqomBkHs=</ds:DigestValue>
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>
pWDatSEbypIUVQR9NFmLkB9kKWjMb6rKWGFFvGqT5tOUILeDhMHUqjCRB9v/g6yYdogC9TRWouhz
...VoZAIBs7EqCbLt7RgpB4GHWc9E3qp65NaCgluw==
        </ds:SignatureValue>
        <ds:KeyInfo>
            <ds:X509Data>
                <ds:X509Certificate>
MIIG+zCCBOOgAwIBAgIHAe2+sRfTfDANBgkqhkiG9w0BAQUFADCBkTELMAkGA1UEBhMCQVQxDTAL
...tvawqBjOfkw1yeDzsDMJHfMuAcpYfrEL
                </ds:X509Certificate>
            </ds:X509Data>
        </ds:KeyInfo>
    </ds:Signature>
</Notification>
  • Kannst du evtl. ein Beispiel zeigen von Ihr signiertes Dokument? Insbesondere, was ist der Inhalt des KeyInfo? In welcher form wird verwendet, um die Zertifikat-Informationen?
  • Vielen Dank für Ihren Hinweis, ich habe die XML. KeyInfo enthält das Zertifikat base64-dekodiert.
  • Leider, nach meinen Recherchen, die RSA-SHA512 ist einfach nicht unterstützt. Ich bekomme die sehr genauen Ausnahme. Die Dekompilierung der CryptoConfig Klasse, vor allem die DefaultNameHT Eigenschaft für eine Liste der unterstützten algorithmen.
  • Hallo Wiktor, ich fürchte, du hast Recht. Ich dekompiliert SignedXml und kann nur finden, einen namespace für rsa-sha1: XmlDsigRSASHA1Url. Ich denke, man könnte dies als eine Antwort; werde es nutzbar zu machen für andere.
  • Würden Sie wissen, jeder andere Weg, um erfolgreich zu überprüfen, ein SHA512 RSA Signatur?
  • Bearbeitet meine Antwort. Ich habe wohl einen Weg gefunden, damit es funktioniert.

InformationsquelleAutor chanser | 2013-12-10
Schreibe einen Kommentar