Security
AESCipher
AESCipher implementa el xifratge AES en mode CBC per a matrius de bytes incrustades en Documents en PDF.
byte[] key = ...; // 128, 192, or 256-bit key
byte[] data = "sensitive data".getBytes();
byte[] ciphertext = AESCipher.encrypt(key, data);
byte[] plaintext = AESCipher.decrypt(key, ciphertext);Per a la xifratge determinista amb un vector d’inicialització explícit:
byte[] iv = new byte[16]; // 128-bit IV
byte[] ciphertext = AESCipher.encryptWithIV(key, iv, data);
byte[] plaintext = AESCipher.decryptWithIV(key, iv, ciphertext);PdfFileSecurity (Seguretat de fitxer)
PdfFileSecurity gestiona el xifratge de contrasenyes i els permisos d’accés a nivell documental. El encryptFile() mètode accepta una contrasenya d’usuari, la contraseïna del propietari, DocumentPrivilege objecte i mida de la clau.
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) elimina el xifratge d’un document xifrat.
DocumentPrivilege
DocumentPrivilege representa les banderes d’autorització del document xifrat. Utilització: getAllowAll() per concedir tots els permisos, getForbidAll() negar-ho tot, o definir permisos individuals a través de: setAllowPrint(), setAllowModifyContents(), setAllowCopy(), i setAllowModifyAnnotations().
Algoritme Enum
El Algorithm enum selecciona la família d’algoritmes criptogràfics:
Algorithm.RC4xifrat de flux RC4 heretatAlgorithm.AESCifrador de bloc AES (recomandat)