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() で設定します。
アルゴリズム Enum
Algorithm 列挙体は暗号アルゴリズムのファミリーを選択します:
Algorithm.RC4— 従来の RC4 ストリーム暗号Algorithm.AES— AES ブロック暗号(推奨)