We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Encryption Issue


Hi,

I am new to PDF Library. I have attached password security image of Adobe Acrobate.
How do i achieve similar functionality.

Method 1:
//create DocumentPrivileges object
DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;
privilege.PrintAllowLevel = 2;
privilege.ChangeAllowLevel = 1;
privilege.CopyAllowLevel = 1;


string file = @"C:\Users\ankur.patel\Desktop\sign\pass\f1040afill - Copy.pdf";
Document PdfDocument = new Document(file);

//create PdfFileSecurity object with input and output files
PdfFileSecurity fileSecurity = new PdfFileSecurity(PdfDocument);
//encrypt file using 256-bit encryption
fileSecurity.EncryptFile("userpassword", "ownerpassword", privilege, KeySize.x256, Algorithm.AES);

Method 2:

/open document
Document document = new Document("input.pdf");
//encrypt PDF
document.Encrypt("user", "owner", 0, CryptoAlgorithm.RC4x128);

How do I use this method to achieve upper desire outcome.

Any help would be appreciated !!!

Hi Ankur,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for a delay in response.

I would request you to share some more details regarding your requirement. Are you interested in setting the document privileges using the second method (i.e using Aspose.Pdf DOM)? Please confirm so we can further investigate for this functionality. Regarding method 1 (using Facades), I think you are already able to set the security privileges as per your requirement. However, I modified the code a bit to setup the exact same options as per your screen shot for your reference:

//create DocumentPrivileges object

DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

privilege.PrintAllowLevel = 2;

privilege.ChangeAllowLevel = 1;

privilege.CopyAllowLevel = 2;

string file = @"d:\ap data\august2012\HelloWorld.pdf";

Document PdfDocument = new Document(file);

//create PdfFileSecurity object with input and output files

PdfFileSecurity fileSecurity = new PdfFileSecurity(PdfDocument);

//encrypt file using 128-bit encryption

fileSecurity.EncryptFile("userpassword", "ownerpassword", privilege, KeySize.x128, Algorithm.AES);

fileSecurity.Save(file);

Sorry for the inconvenience,

Hi,

Thank you so much for you quick reply…

method 1 (using Facades) works fine.

I am not sure how we achieve same functionality using method 2…

document.Encrypt(“user”, “owner”, 0, CryptoAlgorithm.AESx128);

But Method 1 solve me problem…

thank you once again !!!

Hi Ankur,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

I am glad to know that you are able to achieve your desired results with method 1. Regarding method 2, I am afraid setting DocumentPrivilege using Aspose.Pdf DOM is not supported at the moment. I have created a new feature request in our issue tracking system with issue id: PDFNEWNET-34170 for our development team to check and see if this can be implemented. As soon as I get a feedback, I will update you via this forum thread.

Sorry for the inconvenience,

The issues you have found earlier (filed as PDFNEWNET-34170) have been fixed in Aspose.Pdf for .NET 9.3.0.

Blog post for this release can be viewed over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Ankur,


Thanks for your patience.

We are pleased to share that the issue reported earlier is fixed. When using the following code snippet, it does not seem to be occurring.

[C#]

using (Document document = new Document(inputFile))<o:p></o:p>

{

DocumentPrivilege documentPrivilege = DocumentPrivilege.ForbidAll;

documentPrivilege.AllowScreenReaders = true;

documentPrivilege.AllowPrint = true;

document.Encrypt("user", "owner", documentPrivilege, CryptoAlgorithm.AESx128, false);

document.Save(outputFile);

}