PDF Encryption & Decryption Your business is spending too much on yearly subscriptions for PDF security and compliance. Consider IronSecureDoc, the Comprehensive PDF Security Solution, which provides solutions for managing SaaS services like digital signing, redaction, encryption, and protection, all for a one-time payment. Explore IronSecureDoc Documentation PDF security is an important aspect of working with PDF files, and IronPDF takes PDF security seriously. With IronPDF, you can encrypt and decrypt PDF files by applying custom metadata and security settings to your PDF. IronPDF supports 128-bit encryption on your encrypted files, the ability to decrypt previously encrypted files (given you have the correct passwords needed to access the file), and apply password protection to your existing or newly created PDF documents. Steps to Convert URL to PDF in C# var pdf = PdfDocument.FromFile("sample.pdf", "password"); pdf.MetaData.Author = "Satoshi Nakamoto"; pdf.SecuritySettings.RemovePasswordsAndEncryption(); pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key"); pdf.Password = "my-password"; The first step to encrypting and decrypting your PDF files using IronPDF is to either create a new PDF file, or load an existing one as we have here. While loading our PDF file using PdfDocument.FromFile, we have passed two parameters to the FromFile method: the first is the PDF's file path and the second is the password to open the encrypted PDF. The next lines are editing the metadata for our encrypted PDF. pdf.MetaData.Author, for example, is used to edit the Author field with our custom string value. Each metadata field can be accessed using pdf.MetaData.field-key, where the field-key is replaced with the name of the field you want to edit, such as Author, Keywords, modifiedDate, etc. This is especially helpful for giving your PDF keywords, which make it easier to find, a customized modified date, a new author, or anything else you require to be customized within the MetaData properties. The next line removes any current passwords and encryptions from the PDF document. This decryption process allows you to save the PDF without any encryption on it or clears it for you to add new encryption settings for the PDF, which is what we'll do next. pdf.SecuritySettings.setting gives you the ability to customize the security settings for your PDF, where setting is replaced by the actual setting you wish to change. For example, pdf.SecuritySettings.MakePdfDocumentReadOnly sets the PDF to be read-only. The PdfSecuritySettings class contains numerous options allowing full customization of the security settings of your PDF, from disallowing user annotations to controlling the printing permission rights; this class ensures proper PDF security is handled securely and efficiently. The pdf.Password is used to change the password for your PDF or set a new one if there isn't already an existing one. This password encrypts the PDF file using strong 128-bit encryption, protecting it against unauthorized access. Once you are happy with the metadata and security settings, you can save the PDF document to the desired file location using SaveAs(). Learn to Set PDF Permissions and Passwords with IronPDF View on GitHub Code https://github.com/iron-software/IronPdf.Examples/tree/main/examples/encryption-and-decryption Download ZIP Related Tutorial Related How-To Guide Class Documentation Get Language Packs Download IronPDF DLL Report an Issue on this page Ready to Get Started? Nuget Downloads 16,244,136 | Version: 2025.11 just released Free NuGet Download Total downloads: 16,244,136 View Licenses
All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)