回答
使用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和PDFWriter(用於權限)的API。
謝謝弗雷德裏克。你也可以提供代碼來解密加密文件嗎? – 2010-09-10 16:55:53
對於哪個版本的iText是可行的? – demaniak 2015-11-24 07:36:34
它看起來像iText已經改變了一點,因爲這個答案被接受。 [Here's](http://developers.itextpdf.com/examples/security/clone-encrypting-decrypting-pdfs)如何在iText 7中加密和解密的示例。並且[here](http://itextsupport.com /apidocs/itext7/7.0.0/)是API文檔的更新位置。 – 2017-03-08 00:01:47
iText支持加密。
使用PDFBox(基於Decrypt.java代碼):
PDDocument document = null;
try
{
document = PDDocument.load(infile);
if(document.isEncrypted())
{
DecryptionMaterial decryptionMaterial = null;
decryptionMaterial = new StandardDecryptionMaterial(password);
document.openProtection(decryptionMaterial);
AccessPermission ap = document.getCurrentAccessPermission();
if(ap.isOwnerPermission())
{
document.setAllSecurityToBeRemoved(true);
document.save(outfile);
}
else
{
throw new IOException(
"Error: You are only allowed to decrypt a document with the owner password.");
}
}
else
{
System.err.println("Error: Document is not encrypted.");
}
}
finally
{
if(document != null)
{
document.close();
}
}
- 1. 加密/解密文件。用於加密/解密的ASCII +1
- 2. 使用Java加密/解密文件
- 3. 用於文件AES加密/解密的Java類
- 4. 3des加密/解密文件java
- 5. 加密和解密pdf文件的方法android
- 6. 將javax.crypto用於文件加密/解密的密鑰存儲區
- 7. 使用解密密鑰加密文件
- 8. Java加密/解密
- 9. 文件加密和解密在Java中,不工作解密
- 10. Java - 從配置文件加密/解密用戶名和密碼
- 11. 加密和解密文件
- 12. 解密EFS加密文件
- 13. 加密/解密文件
- 14. 加密/解密文件?
- 15. 文件加密和解密
- 16. 加密/解密文件
- 17. 文件加密和解密
- 18. 解密和加密文件
- 19. 解密250MB PDF文件
- 20. 加密PHP,解密Java
- 21. 解密加密文件會破壞文件? Android的 - Java的
- 22. JavaScript的加密-java解密
- 23. 我如何從Java加密文件加密的文件中解密objective-c
- 24. PDF加密/解密在android中?
- 25. 閱讀加密的PDF元數據不解密文件
- 26. J2ME - mp3文件的加密和解密
- 27. VB.net中的加密 - 解密文件大於源文件?
- 28. C#(加密)和Java(解密)之間的AES加密/解密
- 29. 使用Java解密Android上的OpenSSL加密文件
- 30. 解密用java和AES文件中的OBJ-C加密
你打算如何展示他們 「不正常」 的用戶?他們應該帶他們的私鑰(可能是智能卡)? – Bozho 2010-09-09 11:57:33