public class PublicKeyDecryptionMaterial extends DecryptionMaterial
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.
PDDocument.openProtection(DecryptionMaterial)
Constructor | Description |
---|---|
PublicKeyDecryptionMaterial(java.security.KeyStore keystore,
java.lang.String a,
java.lang.String pwd) |
Create a new public key decryption material.
|
Modifier and Type | Method | Description |
---|---|---|
java.security.cert.X509Certificate |
getCertificate() |
Returns the certificate contained in the keystore.
|
java.lang.String |
getPassword() |
Returns the password given by the user and that will be used
to open the private key.
|
java.security.Key |
getPrivateKey() |
returns The private key that will be used to open the document protection.
|
public PublicKeyDecryptionMaterial(java.security.KeyStore keystore, java.lang.String a, java.lang.String pwd)
keystore
- The keystore were the private key and the certificate area
- 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.public java.security.cert.X509Certificate getCertificate() throws java.security.KeyStoreException
java.security.KeyStoreException
- If there is an error accessing the certificate.public java.lang.String getPassword()
public java.security.Key getPrivateKey() throws java.security.KeyStoreException
java.security.KeyStoreException
- If there is an error accessing the key.