try {
final PrivateKeyInfo pkInfo = KeyStoreUtils.getPkInfo(options);
final PrivateKey key = pkInfo.getKey();
final Certificate[] chain = pkInfo.getChain();
options.log("console.createPdfReader", options.getInFile());
PdfReader reader;
try {
// try to read without password
reader = new PdfReader(options.getInFile());
} catch (Exception e) {
try {
reader = new PdfReader(options.getInFile(), new byte[0]);
} catch (Exception e2) {
reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStr().getBytes());
}
}
options.log("console.createOutPdf", outFile);
fout = new FileOutputStream(outFile);
final HashAlgorithm hashAlgorithm = options.getHashAlgorithmX();
options.log("console.createSignature");
char tmpPdfVersion = '\0'; // default version - the same as input
if (reader.getPdfVersion() < hashAlgorithm.getPdfVersion()) {
tmpPdfVersion = hashAlgorithm.getPdfVersion();
options.log("console.updateVersion", new String[] { String.valueOf(reader.getPdfVersion()),
String.valueOf(tmpPdfVersion) });
}
final PdfStamper stp = PdfStamper.createSignature(reader, fout, tmpPdfVersion, null, options.isAppendX());
if (!options.isAppendX()) {
// we are not in append mode, let's remove existing signatures