dic.put(PdfName.R, new PdfNumber(revision));
try {
recipients = publicKeyHandler.getEncodedRecipients();
} catch (Exception f) {
throw new ExceptionConverter(f);
}
if (revision == STANDARD_ENCRYPTION_40) {
dic.put(PdfName.V, new PdfNumber(1));
dic.put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_S4);
dic.put(PdfName.RECIPIENTS, recipients);
} else if (revision == STANDARD_ENCRYPTION_128 && encryptMetadata) {
dic.put(PdfName.V, new PdfNumber(2));
dic.put(PdfName.LENGTH, new PdfNumber(128));
dic.put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_S4);
dic.put(PdfName.RECIPIENTS, recipients);
} else {
dic.put(PdfName.R, new PdfNumber(AES_128));
dic.put(PdfName.V, new PdfNumber(4));
dic.put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_S5);
PdfDictionary stdcf = new PdfDictionary();
stdcf.put(PdfName.RECIPIENTS, recipients);
if (!encryptMetadata)
stdcf.put(PdfName.ENCRYPTMETADATA, PdfBoolean.PDFFALSE);
if (revision == AES_128)
stdcf.put(PdfName.CFM, PdfName.AESV2);
else
stdcf.put(PdfName.CFM, PdfName.V2);
PdfDictionary cf = new PdfDictionary();
cf.put(PdfName.DEFAULTCRYPTFILTER, stdcf);
dic.put(PdfName.CF, cf);
if (embeddedFilesOnly) {
dic.put(PdfName.EFF, PdfName.DEFAULTCRYPTFILTER);
dic.put(PdfName.STRF, PdfName.IDENTITY);
dic.put(PdfName.STMF, PdfName.IDENTITY);
}
else {
dic.put(PdfName.STRF, PdfName.DEFAULTCRYPTFILTER);
dic.put(PdfName.STMF, PdfName.DEFAULTCRYPTFILTER);
}
}
MessageDigest md = null;
byte[] encodedRecipient = null;
try {
md = MessageDigest.getInstance("SHA-1");
md.update(publicKeyHandler.getSeed());
for (int i = 0; i < publicKeyHandler.getRecipientsSize(); i++) {
encodedRecipient = publicKeyHandler.getEncodedRecipient(i);
md.update(encodedRecipient);
}
if (!encryptMetadata)
md.update(new byte[] { (byte) 255, (byte) 255, (byte) 255,
(byte) 255 });
} catch (Exception f) {
throw new ExceptionConverter(f);
}
byte[] mdResult = md.digest();
setupByEncryptionKey(mdResult, keyLength);