The C14n spec said clearly that c14n documents must not contain XML declaration.
extract from http://www.w3.org/TR/2001/REC-xml-c14n-20010315 --------------------------------------------------------- 4.1 No XML Declaration The XML declaration, including version number and character encoding is omitted from the canonical form. The encoding is not needed since the canonical form is encoded in UTF-8. The version is not needed since the absence of a version number unambiguously indicates XML 1.0. Future versions of XML will be required to include an XML declaration to indicate the version number. However, canonicalization method described in this specification may not be applicable to future versions of XML without some modifications. When canonicalization of a new version of XML is required, this specification could be updated to include the XML declaration as presumably the absence of the XML declaration from the XPath data model can be remedied by that time (e.g. by reissuing a new XPath based on the Infoset data model). ---------------------- Regards, On 2/9/06, Fabio Mondelli <[EMAIL PROTECTED]> wrote: > Hello, > I want to sign and verify xml files. > > in my case, the signed file does not contain the first line: <?xml > version="1.0" encoding="UTF-8"?> from the original document. > > what could be the reason? Im doing a enveloped xml signature. > > here is the code: > > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > dbf.setNamespaceAware(true); > DocumentBuilder db = dbf.newDocumentBuilder(); > Document doc = > db.parse(parameterObject.getUnsignedInputXMLFile()); > String BaseURI = > parameterObject.getSignedXMLFile().toURL().toString(); > XMLSignature sig = new XMLSignature(doc, BaseURI, > XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1); > ... > > > Element rootElement = doc.getDocumentElement(); > rootElement.insertBefore(sig.getElement(), > rootElement.getFirstChild()); > sig.addResourceResolver(new OfflineResolver()); > Transforms transforms = new Transforms(doc); > > transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE); > transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS); > > thank U! > -- http://r-bg.com
