} else {
signedData = signedDataGenerator.generate(content, encapsulate);
}
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());
ASN1Primitive asn1Primitive = BouncyCastleProviderHelper.toASN1Primitive(timeStamp.getEncoded());
DERSet derSet = new DERSet(asn1Primitive);
Hashtable hashtable = new Hashtable();
Attribute attribute = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, derSet);
hashtable.put(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, attribute);
AttributeTable unsignedAtts = new AttributeTable(hashtable);
list.add(SignerInformation.replaceUnsignedAttributes(signerInformation, unsignedAtts));
}
SignerInformationStore tmpSignerInformationStore = new SignerInformationStore(list);
signedData = CMSSignedData.replaceSigners(signedData, tmpSignerInformationStore);
}
return signedData.getEncoded();