}
// Open output file for writing.
FileOutputStream output = new FileOutputStream(outputFileName);
File temp = File.createTempFile("tmp", ".tmp");
PdfStamper stamper = PdfStamper.createSignature(
reader, output, '\0', temp, true);
// Create a DSS (Document Security Store).
LtvVerification verification = stamper.getLtvVerification();
// Add certificates, OCSP responses and CRLs to DSS.
for (String signature : certMap.keySet()) {
ArrayList<byte[]> certificates = new ArrayList<byte[]>();
for (X509Certificate certificate : certMap.get(signature)) {
certificates.add(certificate.getEncoded());
}
ArrayList<byte[]> ocsps = new ArrayList<byte[]>();
for (BasicOCSPResp response : ocspMap.get(signature)) {
ocsps.add(response.getEncoded());
}
ArrayList<byte[]> crls = new ArrayList<byte[]>();
for (X509CRL crl : crlMap.get(signature)) {
crls.add(crl.getEncoded());
}
verification.addVerification(signature, ocsps, crls, certificates);
}
// Timestamp the document.
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
TSAClientBouncyCastle client = new TSAClientBouncyCastle(
timestampURL,
timestampUser,
timestampPassword,
TSAClientBouncyCastle.DEFAULTTOKENSIZE * 2,