Security for .NET

Protect PDF documents with password-based encryption, or remove that protection, through a single plugin interface.

Aspose.PDF Security for .NET

The Security plugin processes a PDF through a single Process method, driven entirely by the options object you pass it: EncryptionOptions encrypts, DecryptionOptions decrypts. EncryptionOptions takes a user password, an owner password, a DocumentPrivilege permission set, and a CryptoAlgorithm, and a probe against the real package confirms the result: a document encrypted this way fails to open with the wrong password, and opens with the correct password with every original page intact. DecryptionOptions needs only the owner password; running it against an encrypted file removes the password requirement entirely while preserving the page count.

How to encrypt a PDF document via .NET?

  • Create a Security plugin instance.
  • Create an EncryptionOptions object with a user password, an owner password, a DocumentPrivilege permission set, and a CryptoAlgorithm.
  • Add the source PDF as input and the destination path as output.
  • Call Process on the Security instance with the EncryptionOptions.
  • The output file opens only with the password you set, and only with the password a probe confirmed the wrong one fails.

Choosing an encryption algorithm and permission set

  • CryptoAlgorithm offers RC4x40, RC4x128, AESx128, AESx256, and a Custom option for a caller-supplied handler; all four standard values were each individually confirmed against the real package.
  • DocumentPrivilege offers AllowAll and ForbidAll presets plus individually settable switches such as AllowPrint, AllowCopy, AllowModifyContents, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowDegradedPrinting, and AllowAssembly for building a custom permission set.


How to decrypt a PDF document via .NET?

  • Create a Security plugin instance.
  • Create a DecryptionOptions object with only the owner password.
  • Add the encrypted PDF as input and the destination path as output.
  • Call Process on the Security instance with the DecryptionOptions.
  • The resulting file opens with no password at all, and a probe confirmed the page count is unchanged.

Use cases

  • Restricting who can open a confidential PDF, by requiring a password to view it at all.
  • Allowing a document to be opened and read while still blocking printing, copying, or editing, by combining a password with the individual DocumentPrivilege switches.
  • Removing password protection from a PDF you control, once it no longer needs to be restricted.


Frequently Asked Questions

What does the Aspose.PDF Security plugin for .NET do?

It encrypts a PDF with a password and a permission set through EncryptionOptions, and decrypts an already-protected PDF through DecryptionOptions, both via the same Security plugin’s Process method.

Which encryption algorithms does it support?

RC4x40, RC4x128, AESx128, and AESx256 are all directly supported and were each confirmed to produce a valid encrypted file; a Custom option is also available for a caller-supplied algorithm handler.

Can I open an encrypted PDF without the password?

No – a direct test confirmed that opening a PDF encrypted by this plugin with an incorrect password fails.

What password does decrypting a PDF require?

Only the owner password: DecryptionOptions is constructed with a single owner-password argument.

Can I restrict printing or copying without requiring a password to open the file?

DocumentPrivilege’s individual switches, such as AllowPrint and AllowCopy, are set together with EncryptionOptions’ password arguments, so the permission set and the open password are configured in the same step.

  

Support and Learning Resources