Click or drag to resize
Pdf Library for .NET

PdfSecurityManager Class

Applies security to an existing PDF document: encryption (passwords, permissions, key size and algorithm) and digital signing with a PFX certificate. Load a document with one of the Load overloads, configure it, then persist with Save(String) / GetDocument.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalPdfSecurityManager

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.5
Syntax
public class PdfSecurityManager : IDisposable

The PdfSecurityManager type exposes the following members.

Constructors
 NameDescription
Public methodPdfSecurityManagerInitializes a new instance of the PdfSecurityManager class.
Top
Properties
 NameDescription
Public propertyCanAccessibilityCopyContentGets or sets whether copying content for accessibility is allowed.
Public propertyCanAssembleDocumentGets or sets whether assembling the document is allowed.
Public propertyCanCopyContentGets or sets whether copying content is allowed.
Public propertyCanEditAnnotationsGets or sets whether editing annotations is allowed.
Public propertyCanEditContentGets or sets whether editing content is allowed.
Public propertyCanFillFieldsGets or sets whether filling form fields is allowed.
Public propertyCanFullQualityPrintGets or sets whether full-quality printing is allowed.
Public propertyCanPrintGets or sets whether printing is allowed.
Public propertyDigestAlgorithm Gets or sets the hash algorithm the signature added by Sign is computed with.
Public propertyEnableLtv Gets or sets a value indicating whether the signature added by Sign is made LTV-enabled (long-term validation) when the document is saved.
Public propertyEncryptionAlgorithm Gets or sets the encryption algorithm. Defaults to AES for a document that is not encrypted; an encrypted document keeps its own.
Public propertyEncryptionKeySize Gets or sets the encryption key size. Defaults to EncryptKey256BitRevision6 (AES-256) for a document that is not encrypted; an encrypted document keeps its own.
Public propertyEncryptMetadata Gets or sets whether the document's XMP metadata stream is encrypted with the rest of the document. The default value is true, or what the loaded document already does.
Public propertyOwnerPasswordGets or sets the owner (permissions) password.
Public propertyRevocationCheckEnabled Gets or sets whether ValidateSignatures asks the issuer of each signer's certificate whether it has been revoked, through OCSP or a certificate revocation list. The default value is false.
Public propertySignatureBackgroundImage Gets or sets an image drawn behind the text of the visible signature Sign adds - a company logo, a seal, a scanned handwritten signature - in place of the default mark.
Public propertySignatureBackgroundOpacity Gets or sets how strongly the background of the visible signature is drawn, from 0 (no background) to 1 (the image's own colours).
Public propertyUserPasswordGets or sets the user (open) password.
Top
Methods
 NameDescription
Public methodCloseCloses the loaded document and releases its resources.
Public methodStatic memberCompleteExternalSignature(Byte, String, String, IListByte, PdfSignatureDigest, Byte) Writes the signature value into a prepared document held in memory and returns the signed document.
Public methodStatic memberCompleteExternalSignature(String, String, String, IListByte, PdfSignatureDigest, Byte) Writes the signature value into a document prepared with PrepareExternalSignature(IListByte, String) and saves the signed document.
Public methodDispose Releases the loaded document, the same as Close. Lets the PdfSecurityManager be used in a using statement. Calling it after Close, or more than once, does nothing.
Public methodGetDocumentReturns the current state as a new PdfDocument.
Public methodLoad(Byte)Loads a PDF document from a byte array.
Public methodLoad(PdfDocument)Loads an existing PdfDocument.
Public methodLoad(Stream)Loads a PDF document from a stream.
Public methodCode exampleLoad(String)Loads a PDF document from a file.
Public methodLoad(Byte, String)Loads a password-protected PDF document from a byte array.
Public methodLoad(PdfDocument, String)Loads an existing PdfDocument with a password.
Public methodLoad(Stream, String)Loads a password-protected PDF document from a stream.
Public methodLoad(String, String)Loads a password-protected PDF document from a file.
Public methodPrepareExternalSignature(IListByte, String) Prepares the PDF document for a signature produced later, outside this call: the document is given a signature field with an empty, reserved signature, and the request to be signed is returned.
Public methodPrepareExternalSignature(IListByte, String, String, String, String, Int32, RectangleF) Prepares the PDF document for a signature produced later, recording the reason, location and contact info and placing a visible signature on the given page.
Public methodSaveSaves the document (with the applied security) and returns the bytes.
Public methodSave(Stream)Saves the document (with the applied security) to a stream.
Public methodCode exampleSave(String)Saves the document (with the applied security) to a file.
Public methodSign(IPdfExternalSigner) Signs the PDF document with an external signer - a key held in a hardware security module, a smart card or a key service.
Public methodSign(IPdfExternalSigner, String)Signs the PDF document with an external signer.
Public methodCode exampleSign(String, String)Signs the PDF document with the specified PFX certificate.
Public methodSign(String, String, String)Signs the PDF document with the specified PFX certificate.
Public methodSign(IPdfExternalSigner, String, String, String, String)Signs the PDF document with an external signer, recording the reason, location and contact info.
Public methodSign(String, String, String, String, String, String)Signs the PDF document, recording the reason, location and contact info.
Public methodSign(IPdfExternalSigner, String, String, String, String, Int32, RectangleF)Signs the PDF document with an external signer and places a visible signature on the given page.
Public methodSign(IPdfExternalSigner, String, String, String, String, Int32, RectangleF, TimeStampAuthority) Signs the PDF document with an external signer and, optionally, timestamps it via the specified time-stamp authority.
Public methodSign(String, String, String, String, String, String, Int32, RectangleF)Signs the PDF document and places a visible signature on the given page.
Public methodSign(String, String, String, String, String, String, Int32, RectangleF, TimeStampAuthority) Signs the PDF document and, optionally, timestamps it via the specified time-stamp authority.
Public methodValidateSignatures Validates every digital signature of the loaded document, trusting the certificates in the system's trusted store.
Public methodValidateSignatures(PdfDigitalCertificatesCollection) Validates every digital signature of the loaded document, trusting the given certificates as roots - for example your organisation's own certificate authority - in addition to the system's trusted store.
Top
Example
PdfSecurityManager manager = new PdfSecurityManager();
manager.Load("document.pdf");
manager.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES;
manager.EncryptionKeySize = PdfEncryptionKeySize.EncryptKey128Bit;
manager.UserPassword = "open123";
manager.OwnerPassword = "owner456";
manager.CanPrint = true;
manager.Save("encrypted.pdf");
manager.Close();
See Also