I need to sign a XML with a specific format, I have an example of what I should get but I'm not being able to replicate it

36 views Asked by At

In the correct form of the file there are thee fields coming from the same .pfx certificate and ends with something like this:

<ds:X509Data>
    <ds:X509Certificate>
    MIIHYTCCBkmgAwIBA....
    </ds:X509Certificate>
    <ds:X509Certificate>
    MIIFgzCCA2ugAwIB...
    </ds:X509Certificate>
    <ds:X509Certificate>
    MIIG2jCCBMKgAw...
    </ds:X509Certificate>
</ds:X509Data>

But with my Java code:

XMLSignature sig = new XMLSignature(doc, null, XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512);
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream(certificado), contraseƱa);
X509Certificate cert = (X509Certificate) ks.getCertificate(ks.aliases().nextElement());
sig.addKeyInfo(cert);
sig.addKeyInfo(cert.getPublicKey());
<ds:X509Data>
    <ds:X509Certificate>
    MIIHYTCCBkmgAwIBA...
    </ds:X509Certificate>
</ds:X509Data>

Which it's only the first field of the three ones...

Any idea?

0

There are 0 answers