0

我需要在 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);
4

1 回答 1

0

目前无法将其他数据对象添加到计数器签名中。属性的生成包括引用目标签名元素的Countersignature单个数据对象:ds:SignatureValue

https://code.google.com/p/xades4j/source/browse/trunk/src/main/java/xades4j/production/DataGenCounterSig.java

该类CounterSignatureProperty可能会获得一个SignedDataObjects包含在计数器签名中的实例:

https://code.google.com/p/xades4j/source/browse/trunk/src/main/java/xades4j/properties/CounterSignatureProperty.java

于 2013-11-25T19:26:06.740 回答