Security
编码器:AESCipher
AESCipher 在CBC模式中实现AES加密,用于嵌入的字节阵列. 文件.
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);对于使用明确初始化向量进行确定性加密:
byte[] iv = new byte[16]; // 128-bit IV
byte[] ciphertext = AESCipher.encryptWithIV(key, iv, data);
byte[] plaintext = AESCipher.decryptWithIV(key, iv, ciphertext);文件安全性
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 enum 选择了加密算法家族:
Algorithm.RC4旧的RC4流密码Algorithm.AESAES块密码 (建议)