我需要在 CounterSignature 中插入一个名为“xmldsig-my-object”的 ds:Object,以使用 xades4j 库形成以下 xml 结构:
<ds:Signature>
...
<ds:Object>
...
<xades:UnsignedProperties>
<xades:UnsignedSignatureProperties>
<xades:CounterSignature>
<ds:Signature>
<ds:SignedInfo>
<ds:Reference Id... Type="xmldsig#Object" URI="xmldsig-my-object">
// !!! here I need to add reference to my-object
</ds:Reference>
</ds:SignedInfo>
<ds:Object Id="xmldsig-my-object">
// !!! here I need to add my-object
</ds:Object>
</ds:Signature>
</xades:CounterSignature>
</xades:UnsignedSignatureProperties>
</xades:UnsignedProperties>
</ds:Object>
</ds:Signature>
我生成 xades 签名,然后用会签(元素签名节点)丰富它:
Element signatureNode = ...;
XadesSignatureFormatExtender extender = new XadesFormatExtenderProfile()
.getFormatExtender();
XMLSignature sig = new XMLSignature(signatureNodeToEnrich, "");
try {
final XadesSigner counterSigner =
new XadesTSigningProfile(myKeyingDataProvider)
.withPolicyProvider(mySignaturePolicyInfoProvider)
.withAlgorithmsProviderEx(myXadesAlgorithmsProviderEx)
.withTimeStampTokenProvider(myTimeStampTokenProvider())
.newSigner();
Collection<UnsignedSignatureProperty> usp = new ArrayList<>(1);
usp.add(new CounterSignatureProperty(counterSigner));
extender.enrichSignature(sig, new UnsignedProperties(usp));
} catch (Exception exc) {
exc.printStackTrace(System.out);
throw exc;
}
我应该怎么做才能以通常的方式将对象添加到 CuterSignature 的 SignedInfo 引用中:
SignedDataObjects signedObjs = new SignedDataObjects();
Document docObj1 = createDocument();
.....................
DataObjectDesc myObj1 = new EnvelopedXmlObject(..., "text/xml", null);
signedObjs.withSignedDataObject(myObj1);
signer = new XadesTSigningProfile(...).newSigner();
signer.sign(signedObjs, docDest);