Security

AESCipher

AESCipher implementerar AES-kryptering i CBC-läge för bytearrader som är inbyggda i PDF dokumentet är.

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);

För deterministisk kryptering med en uttrycklig initialiseringvektor:

byte[] iv = new byte[16]; // 128-bit IV
byte[] ciphertext = AESCipher.encryptWithIV(key, iv, data);
byte[] plaintext  = AESCipher.decryptWithIV(key, iv, ciphertext);

PdfFil säkerhet

PdfFileSecurity Hantera dokumentnivå lösenord kryptering och åtkomst tillstånd. Den encryptFile() Metoden accepterar ett användarens lösenord, ägarens, DocumentPrivilege objekt och nyckelstorlek.

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) Ta bort kryptering från ett kryptat dokument.

DocumentPrivilege

DocumentPrivilege representerar tillståndsflaggorna för det krypterade dokumentet. Användning getAllowAll() att ge alla tillstånd, getForbidAll() att förneka alla, eller individuella tillstånd genom att setAllowPrint(), setAllowModifyContents(), setAllowCopy(),och setAllowModifyAnnotations().

Algoritm Enum

Den Algorithm Enum väljer den kryptografiska algoritmfamiljen:

  • Algorithm.RC4 - Arv av RC4 stream cipher
  • Algorithm.AES — AES block cipher (rekommenderas)

Se även

 Svenska