我正在使用此代码尝试使用签名 xades-bes 签署 xml:
// 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);
这将返回有关未找到 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
提前感谢您的帮助