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?