IRONSOFTWAREHOME
PDF Encryption & Decryption
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    // Import a PDF document or create a new PDF from Html
    const pdf = await PdfDocument.open("encrypted.pdf", "password");
    
    // Create an empty Map
    const newMetadata = new Map();

    // Add key-value pairs of metadata
    newMetadata.set("Author", "Satoshi Nakamoto");
    newMetadata.set("Keywords", "SEO, Friendly");

    await pdf.overrideMetadata(newMetadata);

    await pdf.removePasswordsAndEncryption();
    // Make PDF read-only
    await pdf.makePdfDocumentReadOnly("secret-key");

    // Configure permissions
    const permissions = {
        AllowAnnotations: false,
        AllowExtractContent: false,
        AllowFillForms: false,
        AllowPrint: true,
    };

    await pdf.setPermission(permissions);
    
    // Change or set the document encrpytion password
    await pdf.saveAs("secured.pdf", {userPassword:"my-password"});
})();
npm i @ironsoftware/ironpdf
PDF Encryption & Decryption

PDF Encryption & Decryption

This code example demonstrates how to modify metadata, make the PDF read-only, configure permissions, and change the document encryption password using IronPDF's powerful C# .NET PDF library.

To begin, import an existing PDF document using the open method. This method can be utilized to open password-protected documents by specifying the password as the second parameter, offering robust handling of secured files.

To set new metadata information, start by creating a dictionary and add key-value pairs for metadata, such as the author and keywords. Utilize the overrideMetadata method in IronPDF to apply the new metadata to the PDF document effectively.

Next, remove passwords and encryption using the removePasswordsAndEncryption method provided by IronPDF, and configure the PDF to be read-only by setting a new password with the makePdfDocumentReadOnly method, ensuring the document's integrity and security.

Permissions for the PDF document are configured using an object named "permissions," which specifies whether certain actions, such as annotations, content extraction, form filling, and printing, are allowed or disallowed. Pass the permissions object to the setPermission method to precisely control the document's accessibility features.

Finally, change or set the document encryption password to "my-password," and save the modified PDF as "secured.pdf," showcasing IronPDF's capability for secure document management in application development.

Explore PDF Encryption & Decryption Code Example
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required