我需要在CounterSignature中插入一个ds:Object - 名为“xmldsig-my-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)来丰富它:
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;
}
如何将对象添加到CouterSignature的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);
答案 0 :(得分:0)
目前无法将其他数据对象添加到计数器签名中。 Countersignature
属性的生成包括引用目标签名的ds:SignatureValue
元素的单个数据对象:
CounterSignatureProperty
类可能会将SignedDataObjects
的实例包含在计数器签名中: