Create AES Encrypted PDFs in C# and VB .NET

Tue, July 31 2012, 2:48 PM (US Eastern Time)

We recently released an update that introduces AES-256 bit and AES-128 bit encryption to our .NET PDF creation and merging library. We have offered encryption since 2002, but this was limited to RC4-40 bit and RC4-128 bit security until this release. We have also restructured the API a bit in order to easily accommodate new encryption methods in the future.

Encryption is now handled by 4 classes in a new ceTe.DynamicPDF.Cryptography namespace:

All security classes allow restrictions to be placed on a PDF to restrict printing, modification, copying content or updating/adding text annotations or form fields. The 128-bit and higher classes allow restrictions to be placed on a PDF to restrict filling in existing form fields, extracting text and graphics for accessibility purposes, modifying the pages included, high resolution printing or leaving the XMP metadata unencrypted. The AES classes also add the ability to encrypt only file attachments.

The C# code to add AES-256 bit encryption to a new document is very straight forward:

Document document = new Document();
Page page = new Page();
page.Elements.Add(new Label("AES-256 bit encrypted PDF.", 0, 0, 500, 15));
document.Pages.Add(page);
// Add the encryption
Aes256Security security = new Aes256Security("ownerpassword", "userpassword");
security.AllowHighResolutionPrinting = false;
// Set other encryption options
document.Security = security;
// Output the PDF
document.Draw("MyPDF.pdf");

The C# code to add AES-256 bit encryption to an existing PDF is shown below:

MergeDocument document = new MergeDocument("MyInputPDF.pdf");
// Add the encryption
Aes256Security security = new Aes256Security("ownerpassword", "userpassword");
security.AllowHighResolutionPrinting = false;
// Set other encryption options
document.Security = security;
// Output the PDF
document.Draw("MyPDF.pdf");

Keep in mind that AES-256 bit encryption is only supported by Acrobat 9 and above and AES-128 bit encryption by Acrobat 7 and above. Additional information about the security and encryption features can be found in our Help Library at the link below:

Are there any new security or encryption features that you would like to see in our DynamicPDF libraries? Let me know by commenting below.

Tags: , , , ,

Comments (2) -

Renil Abdulkader
3/15/2016 11:40:18 AM #

Hi Andy,

How do we disable the security on a form if we have the password? Basically, we are trying to read the form fields from a secured PDF and it is not identifying it.

Anil S
3/15/2016 2:16:59 PM #

Hello Renil,

Here is the sample code to disable security of a password protected PDF, provided you know the password.

  PdfDocument pdfA = new PdfDocument( @"C:\Encrypted.pdf", "password" );
  MergeDocument document = new MergeDocument(pdfA);
  document.Draw(@"C:\Decrypted.pdf");
  
In your case the form fields issue appears to be not related to the security of the PDF. Please email the actual PDF to our support team (support@cete.com) so we can take a look.

Add comment

biuquote
  • Comment
  • Preview
Loading

Month List

RecentPosts