use of com.tom_roush.pdfbox.pdmodel.encryption.StandardDecryptionMaterial in project PdfBox-Android by TomRoush.
the class COSParser method prepareDecryption.
/**
* Prepare for decryption.
*
* @throws InvalidPasswordException If the password is incorrect.
* @throws IOException if something went wrong
*/
private void prepareDecryption() throws IOException {
if (encryption != null) {
return;
}
COSBase trailerEncryptItem = document.getTrailer().getItem(COSName.ENCRYPT);
if (trailerEncryptItem == null || trailerEncryptItem instanceof COSNull) {
return;
}
if (trailerEncryptItem instanceof COSObject) {
COSObject trailerEncryptObj = (COSObject) trailerEncryptItem;
parseDictionaryRecursive(trailerEncryptObj);
}
try {
encryption = new PDEncryption(document.getEncryptionDictionary());
DecryptionMaterial decryptionMaterial;
if (keyStoreInputStream != null) {
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(keyStoreInputStream, password.toCharArray());
decryptionMaterial = new PublicKeyDecryptionMaterial(ks, keyAlias, password);
} else {
decryptionMaterial = new StandardDecryptionMaterial(password);
}
securityHandler = encryption.getSecurityHandler();
securityHandler.prepareForDecryption(encryption, document.getDocumentID(), decryptionMaterial);
accessPermission = securityHandler.getCurrentAccessPermission();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException("Error (" + e.getClass().getSimpleName() + ") while creating security handler for decryption", e);
} finally {
if (keyStoreInputStream != null) {
IOUtils.closeQuietly(keyStoreInputStream);
}
}
}
Aggregations