Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Sep 12, 2024 3:21 pm

Hi !

I just upgraded my .NET project with the latest version of Spire.PDF.

I always used the "document.Security.Encrypt(...)" but, now, I have the message that this method is obsolete.

I can't understand which is the new one ... can someone help me ?

Thanks !
User avatar

luca.demori
 
Posts: 12
Joined: Fri Mar 23, 2018 1:55 pm

Fri Sep 13, 2024 8:06 am

Hello,

Thanks for your inquiry.
In order to optimize this functionality, we have made an improvement, and the latest version currently uses the following code.

Encrypt document:
Code: Select all
 PdfDocument doc = new PdfDocument();
  doc.LoadFromFile(@"in.pdf");
  //Create password security policy
  PdfSecurityPolicy securityPolicy = new PdfPasswordSecurityPolicy(userPassword, ownerPassword); 
  //Set encryption algorithm
  securityPolicy.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES_128; 
  //Set document permissions (ownership), do not set default to ForbidAll
  securityPolicy.DocumentPrivilege = PdfDocumentPrivilege.AllowAll; 
  //Set printing permissions
  securityPolicy.DocumentPrivilege.AllowPrint = false;
  doc.Encrypt(securityPolicy);
  doc.SaveToFile(@"out.pdf");


Decrypt document:
Code: Select all
   PdfDocument doc = new PdfDocument();
   doc.LoadFromFile(@"in.pdf", ownerPassword);
   doc.Decrypt();
   doc.SaveToFile(@"out.pdf");

The method you used will be removed in the future, now we recommend using the new interface to implement document encryption and decryption(from 9.7.14). If there is any other issues, please feel free to provide feedback.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Fri Sep 13, 2024 1:25 pm

Thanks Amin, it works great !

Thanks for your support !
User avatar

luca.demori
 
Posts: 12
Joined: Fri Mar 23, 2018 1:55 pm

Sat Sep 14, 2024 1:24 am

Hello,

Thanks for your reply.
I'm glad to hear this news. If you have any other questions, please feel free to write to me.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF

cron