签名上的结果证书具有“ ”如何删除它们?

时间:2019-01-17 17:19:22

标签: java xades4j

我正在使用xades4j唱歌xml,一切正常。 但是在生成的XML上,X509Certificate看起来像这样:

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

如何删除“&#13;”从那里来吗?

执行签名的方法是这样的:

@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;
}

1 个答案:

答案 0 :(得分:1)

我花了几个小时才解决,但我终于在这里找到了解决方案:https://bugs.openjdk.java.net/browse/JDK-8264194

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