Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Encrypting a PDF document protects its content from unauthorized access from outside, especially during file sharing or archiving.
Confidential PDF documents can be encrypted and password protected. Only user who know the password will be able to decrypt, open and view these documents.
Let’s take a look at how PDF encryption works with Aspose.PDF library.
In order to encrypt a PDF file, you need to create PdfFileSecurity object and then call the EncryptFile method. You can pass user password, owner password and privileges to EncryptFile method. You also need to pass KeySize and Algorithm values to this method.
Review a possible list of such CryptoAlgorithm:
Member name | Value | Description |
---|---|---|
RC4x40 | 0 | RC4 with key length 40. |
RC4x128 | 1 | RC4 with key length 128. |
AESx128 | 2 | AES with key length 128. |
AESx256 | 3 | AES with key length 256. |
The following code snippet shows you how to encrypt PDF file.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void EncryptPDFFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var fileSecurity = new Aspose.Pdf.Facades.PdfFileSecurity())
{
// Bind PDF document
fileSecurity.BindPdf(dataDir + "input.pdf");
// Encrypt file using 256-bit encryption
fileSecurity.EncryptFile("User_P@ssw0rd", "OwnerP@ssw0rd", Aspose.Pdf.Facades.DocumentPrivilege.Print, Aspose.Pdf.Facades.KeySize.x256,
Aspose.Pdf.Facades.Algorithm.AES);
// Save PDF document
fileSecurity.Save(dataDir + "SampleEncrypted_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.