I am using this code to try to sign an xml, with a signature xades-bes:
// open file
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
Document doc1 = builder.parse(new File(xmlInPath));
Element elemToSign = doc1.getDocumentElement();
DOMHelper.useIdAsXmlId(elemToSign);
kp = new FileSystemKeyStoreKeyingDataProvider("pkcs12", keyPath, new
FirstCertificateSelector(),
new DirectPasswordProvider(password), new
DirectPasswordProvider(password), true);
DataObjectDesc obj = new
DataObjectReference("#DatosEmision").withTransform(new
EnvelopedSignatureTransform());
SignedDataObjects dataObjs = new
SignedDataObjects().withSignedDataObject(obj);
XadesSigningProfile p = new XadesBesSigningProfile(kp);
XadesSigner signer = p.newSigner();
signer.sign(dataObjs, elemToSign);
this returns error referring to not finding the ID:
xades4j.XAdES4jXMLSigException: Cannot resolve element with ID DatosEmision
at xades4j.production.SignerBES.sign(SignerBES.java:277)
at xades4j.production.SignerBES.sign(SignerBES.java:130)
at xadessignergt.Signer.sign(Signer.java:63)
at xadessignergt.Cli.main(Cli.java:24)
Caused by: org.apache.xml.security.signature.ReferenceNotInitializedException:
Cannot resolve element with ID DatosEmision
Thanks in advance for your helps
That's right, the problem was root, I did solve that, but I'm still missing something else, the xml result is adding two "certdigest" to the "object" node, and you have to add only the first one, that is, the following one
shouldn't be.
I pass the code and the part of the signed xml where you see the object that I need to correct:
java code:
signed xml:
Thanks in advance for your helps