我需要加密和解密 pdf 文件。是否有免费或低成本的 Java API 可以做到这一点?基本上我需要对普通用户隐藏文件。关于以编程方式实现该目标的任何其他建议?
谢谢, 深
最佳答案
使用 iText :
// Assuming you provide the following yourself:
File inputFile;
File outputFile;
String userPassword;
String ownerPassword;
// A bit-field containing file permissions.
int permissions = PDFWriter.ALLOW_PRINTING | PDFWriter.ALLOW_COPY;
PdfReader reader = new PdfReader(inputFile);
PdfEncryptor.encrypt(reader, new FileOutputStream(outputFile),
ENCRYPTION_AES128, userPassword, ownerPassword,
permissions);
这是 PDFEncryptor 的 API和 PDFWriter (对于权限)。
关于用于加密/解密 pdf 文件的 Java API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3676004/