Security

AESCipher

AESCipher은(는) PDF 문서에 삽입된 바이트 배열에 대해 CBC 모드의 AES 암호화를 구현합니다.

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

명시적인 초기화 벡터를 사용한 결정적 암호화를 위해:

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

PdfFileSecurity

PdfFileSecurity은(는) 문서 수준 비밀번호 암호화 및 접근 권한을 관리합니다. encryptFile() 메서드는 사용자 비밀번호, 소유자 비밀번호, DocumentPrivilege 객체, 그리고 키 크기를 받아들입니다.

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)은(는) 암호화된 문서에서 암호화를 제거합니다.

DocumentPrivilege

DocumentPrivilege은(는) 암호화된 문서의 권한 플래그를 나타냅니다. 모든 권한을 부여하려면 getAllowAll()을(를) 사용하고, 모든 권한을 거부하려면 getForbidAll()을(를) 사용하거나, 개별 권한은 setAllowPrint(), setAllowModifyContents(), setAllowCopy(), setAllowModifyAnnotations()을(를) 통해 설정합니다.

알고리즘 열거형

Algorithm 열거형은 암호화 알고리즘 패밀리를 선택합니다:

  • Algorithm.RC4 — 레거시 RC4 스트림 암호
  • Algorithm.AES — AES 블록 암호 (권장)

참조

 한국어