org.pdfbox.pdmodel.encryption

Class PublicKeyDecryptionMaterial


public class PublicKeyDecryptionMaterial
extends DecryptionMaterial

This class holds necessary information to decrypt a PDF document protected by the public key security handler. To decrypt such a document, we need: Objects of this class can be used with the openProtection method of PDDocument. The following example shows how to decrypt a document using a PKCS#12 certificate (typically files with a pfx extension).
 PDDocument doc = PDDocument.load(document_path);
 KeyStore ks = KeyStore.getInstance("PKCS12");
 ks.load(new FileInputStream(certificate_path), password.toCharArray());
 PublicKeyDecryptionMaterial dm = new PublicKeyDecryptionMaterial(ks, null, password);
 doc.openProtection(dm);
 
In this code sample certificate_path contains the path to the PKCS#12 certificate.
Version:
$Revision: 1.2 $
Author:
Benoit Guillon (benoit.guillon@snv.jussieu.fr)
See Also:
PDDocument.openProtection(DecryptionMaterial)

Constructor Summary

PublicKeyDecryptionMaterial(KeyStore keystore, String a, String pwd)
Create a new public key decryption material.

Method Summary

X509Certificate
getCertificate()
Returns the certificate contained in the keystore.
String
getPassword()
Returns the password given by the user and that will be used to open the private key.
Key
getPrivateKey()
returns The private key that will be used to open the document protection.

Constructor Details

PublicKeyDecryptionMaterial

public PublicKeyDecryptionMaterial(KeyStore keystore,
                                   String a,
                                   String pwd)
Create a new public key decryption material.
Parameters:
keystore - The keystore were the private key and the certificate are
a - The alias of the private key and the certificate. If the keystore contains only 1 entry, this parameter can be left null.
pwd - The password to extract the private key from the keystore.

Method Details

getCertificate

public X509Certificate getCertificate()
            throws KeyStoreException
Returns the certificate contained in the keystore.
Returns:
The certificate that will be used to try to open the document.

getPassword

public String getPassword()
Returns the password given by the user and that will be used to open the private key.
Returns:
The password.

getPrivateKey

public Key getPrivateKey()
            throws KeyStoreException
returns The private key that will be used to open the document protection.
Returns:
The private key.