CMSTypedData content = new CMSProcessableByteArray(data);
CMSSignedData signedData = cmsSignedDataGenerator.generate(content, true);
if (timeStampClient != null) {
SignerInformationStore signerInformationStore = signedData.getSignerInfos();
List list = new ArrayList();
for (Object o : signerInformationStore.getSigners()) {
SignerInformation signerInformation = (SignerInformation) o;
TimeStamp timeStamp = timeStampClient.getTimeStamp(signerInformation.getSignature());
DERObject derObject = new ASN1InputStream(timeStamp.getEncoded()).readObject();
DERSet derSet = new DERSet(derObject);
Hashtable hashtable = new Hashtable();
Attribute unsignAtt = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, derSet);
hashtable.put(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, unsignAtt);
AttributeTable unsignedAtts = new AttributeTable(hashtable);
list.add(SignerInformation.replaceUnsignedAttributes(signerInformation, unsignedAtts));
}
SignerInformationStore tmpSignerInformationStore = new SignerInformationStore(list);
signedData = CMSSignedData.replaceSigners(signedData, tmpSignerInformationStore);
}
return signedData.getEncoded();