PDF Security for .NET
The ExpertPdf PDF Security library manages the security settings of PDF documents in any .NET application, ASP.NET web sites or Windows Forms applications. Encrypt the content, set user and owner passwords, and control what readers may do: print, copy, assemble the document, fill forms, edit the content or the annotations.
Choose a 40, 128 or 256 bit key and the RC4 or AES algorithm, remove all the security settings with the user or owner password, and sign documents with a PFX certificate. It is a .NET assembly you reference in your application, with no installation.
Everything PDF Security does.
Grouped by how a PDF document is protected: who can open it, what readers can do once it is open, and who signed it.
Lock the document.
User and owner passwords, a 40, 128 or 256 bit key, the RC4 or AES algorithm, applied to existing PDF documents and removed again with a password.
User password
The password required to open the PDF document.
Owner password
The password required to change the permissions of the document, such as printing or editing.
RC4 or AES, 40 to 256 bit
Encrypt the content with the RC4 or AES algorithm and a 40, 128 or 256 bit key. The defaults are AES and a 128 bit key.
Secure existing PDFs
Apply the security settings to a PDF file, or to a PDF document in memory as an array of bytes, for example one produced by another PDF tool.
Remove the security
Remove all the security settings of a document by giving its user or owner password.
AES-256 and non-ASCII passwords
AES-256 is written as revision 6 (ISO 32000-2), and passwords in any language work. The document information is kept when securing or unsecuring.
Control what readers can do.
Each permission is a property of PdfSecurityOptions that allows or denies one operation.
Printing
Allow or deny printing with CanPrint, and printing in full quality with CanFullQualityPrint.
Copying
Allow or deny copying the content with CanCopyContent, and copying it for accessibility with CanAccessibilityCopyContent.
Editing
Allow or deny editing the content of the document with CanEditContent.
Forms and annotations
Separate permissions for filling form fields (CanFillFormFields) and editing annotations (CanEditAnnotations).
Document assembly
Allow or deny creating bookmarks and thumbnails and inserting, rotating or deleting pages, with CanAssembleDocument.
Sign the document.
Sign a PDF document with a PFX certificate, with an optional time stamp, or manage security from the command line.
Digital signatures
The Sign method signs a PDF document with a PFX certificate and its password.
Signature details
Give the signature name, the reason, the location and the contact information, and place the signature on a page, in a rectangle.
Certification signatures
Certify a document as its author, and choose what may change afterwards: nothing, form filling, or form filling and annotations.
Empty signature fields
Add a signature field that a later Sign call with the same name fills in.
In memory and protected sources
Sign from a stream to a stream or from bytes to bytes, and sign or validate password-protected documents with SourcePdfPassword.
Time stamp server
Add a time stamp from a time stamp server, with its address, user name, password and timeout, using TimeStampAuthority.
Validate signatures
ValidateSignatures checks integrity, whole-document coverage, the certificate and its chain, the time stamp and, optionally, revocation, for every signature.
Read the security settings
GetSecurityInfo reports encryption, algorithm and key size, permissions, required passwords and signatures, without changing the file.
Command line sample
A command line sample, with its C# and VB.NET source for .NET Framework and a .NET 10 version, applies or removes the security settings of PDF documents.
A PDF, locked down.
The PdfSecurityManager and PdfSecurityOptions classes: secure a file, remove the security, and secure a PDF document in memory. All the properties and methods are in the API reference.
using ExpertPdf.PDFSecurity; var options = new PdfSecurityOptions(); options.UserPassword = "user-password"; options.OwnerPassword = "owner-password"; options.Algorithm = EncryptionAlgorithm.AES; options.KeySize = EncryptionKeySize.EncryptKey256Bit; // What a reader may do with the document options.CanPrint = true; options.CanCopyContent = false; options.CanEditContent = false; options.CanEditAnnotations = false; var security = new PdfSecurityManager(options); security.SaveSecuredPdfToFile("contract.pdf", "contract-secured.pdf");
The download includes C# and VB.NET samples.
Install from NuGet with dotnet add package ExpertPdf.PdfSecurity, or read the developer's guide.
Security questions, answered.
Common questions about passwords, encryption, permissions and signatures.
What is the difference between the user password and the owner password?
Which encryption algorithms and key lengths are supported?
Algorithm and KeySize properties of PdfSecurityOptions. The defaults are AES and a 128 bit key.Can I secure PDF documents that already exist?
PdfSecurityManager applies the security settings to an existing PDF document, given as a file or as an array of bytes. The in-memory methods work with PDF documents produced by other tools.Can I remove the security from a PDF document?
SaveUnSecuredPdfToFile and GetUnSecuredPdfBytes remove all the security settings when you give them the user or the owner password of the document.Which permissions can I set?
CanPrint) and full quality printing (CanFullQualityPrint), copying the content (CanCopyContent) and copying it for accessibility (CanAccessibilityCopyContent), editing the content (CanEditContent), editing annotations (CanEditAnnotations), filling form fields (CanFillFormFields), and assembling the document: bookmarks, thumbnails, inserting, rotating or deleting pages (CanAssembleDocument). Filling form fields and assembling the document take effect with a 128 bit key.Can it sign PDF documents?
Sign method signs a PDF document with a PFX certificate, from a file, a stream or a byte array. You give the signature name, the reason, the location and the contact information, the page and the rectangle of the signature, and optionally a time stamp server. Set CertificationLevel to certify the document (no changes, form filling, or form filling and annotations allowed afterwards), and use AddSignatureField to add an empty signature field that a later Sign call fills in.Can it check the signatures of a document?
ValidateSignatures checks every signature: whether the document changed after signing, whether the signature covers the whole document, the certificate at signing time, the certificate chain, the time stamp and, optionally, revocation. Each result has a Status of Valid, Unknown or Invalid.Can I read the security settings of a document without changing it?
GetSecurityInfo returns whether the document is encrypted, the algorithm, key size and revision, the permissions, which passwords it needs, and whether it is signed or certified.Is there a ready-to-use tool?
Does it need an installation?
ExpertPdf.PdfSecurity package from NuGet, or copy epsecurepdf.dll from the download to the bin folder of your application and reference it.Which .NET versions and operating systems are supported?
ExpertPdf.PdfSecurity.x64, is also available for applications that run as x64 processes.Is there a free version I can try?
Protect PDF documents in .NET.
Download the free evaluation with C# and VB.NET samples and the command line tool. When you are ready, license it on the pricing page.