{"action":"closed","issue":{"url":"https://api.github.com/repos/yaronn/xml-crypto/issues/35","labels_url":"https://api.github.com/repos/yaronn/xml-crypto/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/yaronn/xml-crypto/issues/35/comments","events_url":"https://api.github.com/repos/yaronn/xml-crypto/issues/35/events","html_url":"https://github.com/yaronn/xml-crypto/issues/35","id":41939048,"number":35,"title":"Signed a particular structure","user":{"login":"marcosomma","id":6088852,"avatar_url":"https://avatars.githubusercontent.com/u/6088852?v=3","gravatar_id":"","url":"https://api.github.com/users/marcosomma","html_url":"https://github.com/marcosomma","followers_url":"https://api.github.com/users/marcosomma/followers","following_url":"https://api.github.com/users/marcosomma/following{/other_user}","gists_url":"https://api.github.com/users/marcosomma/gists{/gist_id}","starred_url":"https://api.github.com/users/marcosomma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcosomma/subscriptions","organizations_url":"https://api.github.com/users/marcosomma/orgs","repos_url":"https://api.github.com/users/marcosomma/repos","events_url":"https://api.github.com/users/marcosomma/events{/privacy}","received_events_url":"https://api.github.com/users/marcosomma/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-09-04T13:49:37Z","updated_at":"2015-12-12T20:52:31Z","closed_at":"2015-12-12T20:52:31Z","body":"Hi all, \r\nI need to generate a XML Signature like this:\r\n\r\n```\r\n         <Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\r\n\t\t\t<SignedInfo>\r\n\t\t\t\t<CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#WithComments\"/>\r\n\t\t\t\t<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\r\n\t\t\t\t<Reference URI=\"\">\r\n\t\t\t\t\t<Transforms>\r\n\t\t\t\t\t\t<Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\r\n\t\t\t\t\t</Transforms>\r\n\t\t\t\t\t<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\r\n\t\t\t\t\t<DigestValue>puV.............3M=</DigestValue>\r\n\t\t\t\t</Reference>\r\n\t\t\t</SignedInfo>\r\n\t\t\t<SignatureValue>Ghog270A................b1rJCpX3A4=</SignatureValue>\r\n\t\t\t<KeyInfo>\r\n\t\t\t\t<X509Data><X509Certificate>MIIEM..................4EsZ3UGyvLWK+O</X509Certificate>\r\n\t\t\t\t</X509Data>\r\n\t\t\t\t<KeyValue>\r\n\t\t\t\t\t<RSAKeyValue>\r\n\t\t\t\t\t\t<Modulus>MIGfMA0GCSqGSIb3DQEBAQU..........T/wIDAQAB</Modulus>\r\n\t\t\t\t\t\t<Exponent>AQAB</Exponent>\r\n\t\t\t\t\t</RSAKeyValue>\r\n\t\t\t\t</KeyValue>\r\n\t\t\t</KeyInfo>\r\n\t\t</Signature>\r\n```\r\n\r\nAnd I have to put it in a specific node ```<security>```.\r\n\r\nThe final result would be something like that:\r\n\r\n```\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<SchufaService version=\"2.0\" xmlns=\"http://www.schufa.de/siml/2.0/final\">\r\n\t<Security>\r\n\t\t<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\r\n\t\t\t<SignedInfo>\r\n\t\t\t\t<CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#WithComments\"/>\r\n\t\t\t\t<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\r\n\t\t\t\t<Reference URI=\"\">\r\n\t\t\t\t\t<Transforms>\r\n\t\t\t\t\t\t<Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\r\n\t\t\t\t\t</Transforms>\r\n\t\t\t\t\t<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\r\n\t\t\t\t\t<DigestValue>puVw.......473M=</DigestValue>\r\n\t\t\t\t</Reference>\r\n\t\t\t</SignedInfo>\r\n\t\t\t<SignatureValue>Ghog2.........X3A4=</SignatureValue>\r\n\t\t\t<KeyInfo>\r\n\t\t\t\t<X509Data>\r\n\t\t\t\t\t<X509Certificate>MIIEMTCCA.....3UGyvLWK+O</X509Certificate>\r\n\t\t\t\t</X509Data>\r\n\t\t\t\t<KeyValue>\r\n\t\t\t\t\t<RSAKeyValue>\r\n\t\t\t\t\t\t<Modulus>MIGf..........IDAQAB</Modulus>\r\n\t\t\t\t\t\t<Exponent>AQAB</Exponent>\r\n\t\t\t\t\t</RSAKeyValue>\r\n\t\t\t\t</KeyValue>\r\n\t\t\t</KeyInfo>\r\n\t\t</Signature>\r\n\t</Security>\r\n\t<Service timestamp=\"2014-09-04T13:16:46.958Z\">\r\n\t\t<Online>\r\n\t\t\t<Request/>\r\n\t\t</Online>\r\n\t</Service>\r\n\t<Data language=\"DEU\">\r\n\t\t<Aktion teilnehmerkennung=\"xxxxxxxxx\" teilnehmerkennwort=\"xxxxxxxxx\">\r\n\t\t\t<AnfrageBonitaetsauskunft version=\"1.0\">\r\n\t\t\t\t<Anfragemerkmal merkmalcode=\"AU\"/>\r\n\t\t\t\t<Verbraucherdaten>\r\n\t\t\t\t\t<Vorname>xxxxxxxxxx</Vorname>\r\n\t\t\t\t\t<Nachname>xxxxxxxxxx</Nachname>\r\n\t\t\t\t\t<Geschlecht>M</Geschlecht>\r\n\t\t\t\t\t<Geburtsdatum>xxxxxxxxxx</Geburtsdatum>\r\n\t\t\t\t\t<AktuelleAdresse>\r\n\t\t\t\t\t\t<Strasse>ZUM xxxxxxx 11</Strasse>\r\n\t\t\t\t\t\t<PLZ>xxxxxx</PLZ>\r\n\t\t\t\t\t\t<Ort>xxxxxxxx</Ort>\r\n\t\t\t\t\t</AktuelleAdresse>\r\n\t\t\t\t</Verbraucherdaten>\r\n\t\t\t</AnfrageBonitaetsauskunft>\r\n\t\t</Aktion>\r\n\t</Data>\r\n</SchufaService>\r\n```\r\n\r\nMy solution to do this is:\r\n\r\n<h5>STEP 1</h5> \r\nCreate all XML like the example:\r\n\r\n```\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<SchufaService version=\"2.0\" xmlns=\"http://www.schufa.de/siml/2.0/final\">\r\n\t<Security>\r\n\t\t<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\r\n\t\t\t<SignedInfo>\r\n\t\t\t\t<CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#WithComments\"/>\r\n\t\t\t\t<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\r\n\t\t\t\t<Reference URI=\"\">\r\n\t\t\t\t\t<Transforms>\r\n\t\t\t\t\t\t<Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/>\r\n\t\t\t\t\t</Transforms>\r\n\t\t\t\t\t<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\r\n\t\t\t\t\t<DigestValue/>\r\n\t\t\t\t</Reference>\r\n\t\t\t</SignedInfo>\r\n\t\t\t<SignatureValue/>\r\n\t\t\t<KeyInfo>\r\n\t\t\t\t<X509Data>\r\n\t\t\t\t\t<X509Certificate>MIIEMTCCA.....3UGyvLWK+O</X509Certificate>\r\n\t\t\t\t</X509Data>\r\n\t\t\t\t<KeyValue>\r\n\t\t\t\t\t<RSAKeyValue>\r\n\t\t\t\t\t\t<Modulus>MIGf..........IDAQAB</Modulus>\r\n\t\t\t\t\t\t<Exponent>AQAB</Exponent>\r\n\t\t\t\t\t</RSAKeyValue>\r\n\t\t\t\t</KeyValue>\r\n\t\t\t</KeyInfo>\r\n\t\t</Signature>\r\n\t</Security>\r\n\t<Service timestamp=\"2014-09-04T13:16:46.958Z\">\r\n\t\t<Online>\r\n\t\t\t<Request/>\r\n\t\t</Online>\r\n\t</Service>\r\n\t<Data language=\"DEU\">\r\n\t\t<Aktion teilnehmerkennung=\"xxxxxxxxx\" teilnehmerkennwort=\"xxxxxxxxx\">\r\n\t\t\t<AnfrageBonitaetsauskunft version=\"1.0\">\r\n\t\t\t\t<Anfragemerkmal merkmalcode=\"AU\"/>\r\n\t\t\t\t<Verbraucherdaten>\r\n\t\t\t\t\t<Vorname>xxxxxxxxxx</Vorname>\r\n\t\t\t\t\t<Nachname>xxxxxxxxxx</Nachname>\r\n\t\t\t\t\t<Geschlecht>M</Geschlecht>\r\n\t\t\t\t\t<Geburtsdatum>xxxxxxxxxx</Geburtsdatum>\r\n\t\t\t\t\t<AktuelleAdresse>\r\n\t\t\t\t\t\t<Strasse>ZUM xxxxxxx 11</Strasse>\r\n\t\t\t\t\t\t<PLZ>xxxxxx</PLZ>\r\n\t\t\t\t\t\t<Ort>xxxxxxxx</Ort>\r\n\t\t\t\t\t</AktuelleAdresse>\r\n\t\t\t\t</Verbraucherdaten>\r\n\t\t\t</AnfrageBonitaetsauskunft>\r\n\t\t</Aktion>\r\n\t</Data>\r\n</SchufaService>\r\n```\r\n\r\n<h5>STEP 2</h5> \r\nGenerate a signature ```getSignatureXml()``` for the ```<data>``` node and extracting the ```DigestValue``` and  ```SignatureValue``` from the result and put these in the relatives nodes of the XML created in the STEP 1.\r\n\r\nthe function to do that is this:\r\n```\r\nfunction getSecurityContent(xml){\r\n    var xml_result = xml.toString();\r\n\r\n    SignedXml.CanonicalizationAlgorithms[\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"] = MyTransformation;\r\n    SignedXml.CanonicalizationAlgorithms[\"http://www.w3.org/2001/10/xml-exc-c14n#WithComments\"] = MyCanonicalization;\r\n\r\n    var sig = new SignedXml();\r\n    sig.addReference(\"//*[local-name(.)='Data']\",[\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"], \"http://www.w3.org/2000/09/xmldsig#sha1\", \"\", \"\", \"\", true);\r\n    sig.signingKey = fs.readFileSync(\"routes/pem/RSA_privkey.pem\");\r\n    sig.canonicalizationAlgorithm = \"http://www.w3.org/2001/10/xml-exc-c14n#WithComments\";\r\n    sig.keyInfoProvider = new FileKeyInfo(\"routes/pem/Cert_public.pem\")\r\n    sig.computeSignature(xml_result);\r\n\r\n    var signature = sig.getSignatureXml();\r\n    var start_digest = '\\<DigestValue>';\r\n    var end_digest = '\\</DigestValue>';\r\n    var temp_digest = '\\<DigestValue/>';\r\n    var start_signature = '\\<SignatureValue>';\r\n    var end_signature = '\\</SignatureValue>';\r\n    var temp_signature = '\\<SignatureValue/>';\r\n    var real_digest = signature.substring((signature.indexOf(start_digest) + start_digest.length), signature.indexOf(end_digest));\r\n    var real_signature = signature.substring((signature.indexOf(start_signature) + start_signature.length), signature.indexOf(end_signature));\r\n\r\n    xml_result = [xml_result.slice(0, xml_result.indexOf(temp_digest)), xml_result.slice(xml_result.indexOf(temp_digest) + temp_digest.length)].join( \"<DigestValue>\" + real_digest.toString() + \"</DigestValue>\");\r\n    xml_result = [xml_result.slice(0, xml_result.indexOf(temp_signature)), xml_result.slice(xml_result.indexOf(temp_signature) + temp_signature.length)].join( \"<SignatureValue>\" + real_signature.toString() + \"</SignatureValue>\");\r\n\r\n    return xml_result.toString();\r\n}\r\n```\r\n\r\n<h5>RESULT</h5>\r\nSO NOT WORK!!!! :(\r\nWhen i try to validate it the response is that \r\n```\r\ninvalid data:data and digest do not match\r\n``` \r\n\r\nAny Ideas???\r\n\r\nThanks"}}