How to Use Security for .NET
The Security class in Aspose.Pdf.LowCode namespace provides a simplified API for encrypting and decrypting PDF documents in .NET applications.
Key Features
- Encrypt a PDF with a password and a permission set, using one of four directly-verified algorithms:
RC4x40,RC4x128,AESx128, orAESx256. - Control exactly what a password-protected reader can do, through
DocumentPrivilege’s individual switches such asAllowPrint,AllowCopy, andAllowModifyContents. - Decrypt a PDF using only the owner password, via
DecryptionOptions. - Process input and output as in-memory streams, using
StreamDataSource, instead of writing temporary files to disk.
Use Cases
- Restrict who can open a confidential PDF, by requiring a password to view it at all.
- Allow a document to be opened and read while still blocking printing or copying, by combining a password with
DocumentPrivilege’s individual switches such asAllowPrintandAllowCopy. - Remove password protection from a PDF you control, once it no longer needs to be restricted.
Setup and Licensing
Apply metered licensing before any conversion:
using Aspose.Pdf;
Metered metered = new Metered();
metered.SetMeteredKey("publicKey", "privateKey");Articles
Prerequisites
- Aspose.PDF for .NET (version 26.10.0 or later)
- Valid Aspose Metered API key
Basic Usage
using Aspose.Pdf.LowCode;
using Aspose.Pdf.Facades;
var security = new Security();
var encryptOptions = new EncryptionOptions(
"userPassword123", "ownerPassword456",
DocumentPrivilege.ForbidAll, CryptoAlgorithm.AESx256);
encryptOptions.AddInput(new FileDataSource("input.pdf"));
encryptOptions.AddOutput(new FileDataSource("encrypted.pdf"));
security.Process(encryptOptions);Advanced Usage with Options
using Aspose.Pdf.LowCode;
using Aspose.Pdf.Facades;
var permissions = DocumentPrivilege.AllowAll;
permissions.AllowPrint = false;
var encryptOptions = new EncryptionOptions(
"userPassword123", "ownerPassword456",
permissions, CryptoAlgorithm.AESx256);
encryptOptions.AddInput(new FileDataSource("input.pdf"));
encryptOptions.AddOutput(new FileDataSource("encrypted.pdf"));
var security = new Security();
security.Process(encryptOptions);