1

I'm using xades4j to sing an xml, everything works fine. But on the resulting XML the X509Certificate looks something like this:

<ds:X509Certificate>  MIIDUjCCAjqgAwIBAgIIYFxFM0GPYwowDQYJKoZIhvcNAQELBQAwKTEMMAoGA1UEAwwDRkVMMQww&#13;
    CgYDVQQKDANTQVQxCzAJBgNVBAYTAkdUMB4XDTE4MTIxMDE1MTQyOFoXDTIwMTIwOTE1MTQyOFow&#13;
    KDERMA8GA1UEAwwIODI1NzYyNTQxEzARBgNVBAoMCnNhdC5nb2IuZ3QwggEiMA0GCSqGSIb3DQEB&#13;
    AQUAA4IBDwAwggEKAoIBAQC6QTYY7yGtmikBaV6pNVee6WzNBToIr3jlFikbvZI4JD+4p0LJqten&#13;
</ds:X509Certificate>

How can I remove the "& #13;" from it?

The method that executes the signature is this one:

@Override
    public DOMSource generarFirmaDigitalParaXML(Document xml, KeyingDataProvider keyingDataProvider, String nombreArchivoXmlOriginal) {
    final Element rootElement = xml.getDocumentElement();
    Element elementoAFirmar = null;
    NodeList nodeList = xml.getElementsByTagName("dte:DatosEmision");

    DOMSource source = null;
    int lenght = nodeList.getLength();
    for (int i = 0; i < lenght; i++) {
        Node nNode = nodeList.item(i);
        elementoAFirmar = (Element) nNode;
    }

    XadesBesSigningProfile profile = new XadesBesSigningProfile(keyingDataProvider);
    try {
        XadesSigner signer = profile.newSigner();
        String atributoUtilizado = seleccionarAttributoComoId(elementoAFirmar, "ID");

        if (atributoUtilizado != null) {
            DataObjectDesc obj = new DataObjectReference("#" + elementoAFirmar.getAttribute(atributoUtilizado))
                    .withTransform(new EnvelopedSignatureTransform());
            SignedDataObjects dataObjs = new SignedDataObjects().withSignedDataObject(obj);
            signer.sign(dataObjs, rootElement);
            xml.setXmlStandalone(true);
            source = new DOMSource(xml);
        } else {
            throw new Exception("Atributo no encontrado en el XML");
        }
    } catch (Exception e) {
        bitacora.log(Level.SEVERE, LOGGER, bitacora.obtenerStackTrace(e), true);
    }
    return source;
}
José Cabrera
  • 153
  • 1
  • 8
  • I think is the XML entity for ascii char 13, which is a carriage return. Maybe this has something to do with the way you are parsing the XML file into the Document instance in the first place. Is this causing issues or did you just want to remove that? – lgoncalves Jan 17 '19 at 23:23
  • I wasn't able to remove it, the Java Transformer adds it, cause is in HTML Mode – José Cabrera Jan 30 '19 at 17:35
  • Any news about how to solve this problem? I've found the same problem but I don't know how to solve it. – Carlos E. Feria Vila May 21 '20 at 07:05

1 Answers1

4

It took me a few hours to resolve it, but I've finally found the solution here: https://bugs.openjdk.java.net/browse/JDK-8264194

static {
    System.setProperty("com.sun.org.apache.xml.internal.security.ignoreLineBreaks", "true");
}
Kosmoski
  • 61
  • 4