I need to encrypt and decrypt pdf files. Is there a free or low cost Java API that does that ? Basically I need to hide files from normal users. Any other suggestion on achieving that programatically ?
Thanks, Deep
How to unlock a PDF to remove password security: Open the PDF in Acrobat. Use the “Unlock” tool: Choose “Tools” > “Protect” > “Encrypt” > “Remove Security.”
Add a password to Adobe Acrobat (pdf)Open the PDF and choose Tools > Protect > Encrypt > Encrypt with Password. If you receive a prompt, click Yes to change the security. Select Require a Password to Open the Document, then type the password in the corresponding field.
Most PDFs can be unlocked! Files with an owner password can be unlocked instantly. However, if the file is thoroughly encrypted, you can only unlock the file by providing the correct password. Just upload your file and the password will be removed from your PDF.
Using PDFBox (based on Decrypt.java code) :
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With