Created
March 25, 2013 13:25
-
-
Save anjackson/5237071 to your computer and use it in GitHub Desktop.
This shows the logic needed to test for two the different PDF encryption modes. It is written in C#, and has been tested with version 1.2.1 of PDFBox, cross-compiled to .net using IKVM (http://www.ikvm.net/).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.WriteLine("Document encrypted = {0}", document.isEncrypted().ToString()); | |
// Can it be opened? | |
bool isOpenable = true; | |
if (document.isEncrypted()) | |
{ | |
DecryptionMaterial decryptionMaterial = new StandardDecryptionMaterial(""); | |
try | |
{ | |
document.openProtection(decryptionMaterial); | |
AccessPermission ap = document.getCurrentAccessPermission(); | |
if (ap.isOwnerPermission()) | |
{ | |
Console.WriteLine("You have owner rights."); | |
} | |
else | |
{ | |
Console.WriteLine("You do not have owner rights."); | |
} | |
} | |
catch (CryptographyException e) | |
{ | |
Console.WriteLine("Cannot open document. :: {0}",e.getMessage()); | |
isOpenable = false; | |
} | |
} | |
Console.WriteLine("Document openable = {0}", isOpenable); | |
// Detailed rights: | |
if (isOpenable) | |
{ | |
Console.WriteLine("Rights: canExtractContent = {0}", document.getCurrentAccessPermission().canExtractContent().ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment