Security
AESCipher
AESCipher implementeert AES-encryptie in CBC-modus voor byte-arrays die in PDF-documenten zijn ingebed.
byte[] key = new byte[32]; // fill with your own 128, 192, or 256-bit key material
byte[] data = "sensitive data".getBytes();
byte[] ciphertext = AESCipher.encrypt(key, data);
byte[] plaintext = AESCipher.decrypt(key, ciphertext);Voor deterministische encryptie met een expliciete initialisatievector:
byte[] iv = new byte[16]; // 128-bit IV
byte[] ciphertext = AESCipher.encryptWithIV(key, iv, data);
byte[] plaintext = AESCipher.decryptWithIV(key, iv, ciphertext);PdfFileSecurity
PdfFileSecurity beheert wachtwoordversleuteling op documentniveau en toegangsrechten. De encryptFile() methode accepteert een gebruikerswachtwoord, eigenaarwachtwoord, DocumentPrivilege object en sleutelgrootte.
try (PdfFileSecurity security = new PdfFileSecurity("input.pdf", "secured.pdf")) {
DocumentPrivilege priv = DocumentPrivilege.getForbidAll();
priv.setAllowPrint(true);
security.encryptFile("userPass", "ownerPass", priv, KeySize.x256);
}decryptFile(ownerPassword) verwijdert encryptie uit een versleuteld document.
DocumentPrivilege
DocumentPrivilege vertegenwoordigt de permissievlaggen voor het versleutelde document. Gebruik getAllowAll() om alle permissies toe te wijzen, getForbidAll() om alle te weigeren, of stel individuele permissies in via setAllowPrint(), setAllowModifyContents(), setAllowCopy() en setAllowModifyAnnotations().
Algoritme Enum
De Algorithm enum selecteert de cryptografische algoritmefamilie:
Algorithm.RC4— legacy RC4-stroomcipherAlgorithm.AES— AES-blokcijfer (aanbevolen)