New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@pdfsmaller/pdf-decrypt

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pdfsmaller/pdf-decrypt

Full-featured PDF decryption with AES-256 and RC4 support. Companion to @pdfsmaller/pdf-encrypt. Powers PDFSmaller.com's PDF unlock tool.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
275
1.48%
Maintainers
1
Weekly downloads
 
Created
Source

@pdfsmaller/pdf-decrypt

Full-featured PDF decryption with AES-256 and RC4 support. Built for browsers, Node.js 18+, Cloudflare Workers, and Deno.

Companion to @pdfsmaller/pdf-encrypt. Powers PDFSmaller.com's Unlock PDF tool.

Features

  • AES-256 decryption (V=5, R=6) — PDF 2.0 standard
  • RC4 40/128-bit decryption (V=1-2, R=2-3) — legacy support
  • User + Owner passwords — accepts either password to decrypt
  • Batched async decryption — processes thousands of objects without browser freeze
  • Web Crypto API — no native dependencies, works everywhere
  • Lightweight — ~18KB total (crypto + decryption logic)
  • Zero dependencies — only pdf-lib as a peer dependency
  • TypeScript types included

Installation

npm install @pdfsmaller/pdf-decrypt pdf-lib

Quick Start

import { decryptPDF } from '@pdfsmaller/pdf-decrypt';
import fs from 'fs';

const pdfBytes = fs.readFileSync('encrypted.pdf');
const decrypted = await decryptPDF(new Uint8Array(pdfBytes), 'my-password');
fs.writeFileSync('decrypted.pdf', decrypted);

API

decryptPDF(pdfBytes, password)

Decrypt a password-protected PDF. Supports both AES-256 and RC4 encryption — the algorithm is detected automatically.

ParameterTypeDescription
pdfBytesUint8ArrayThe encrypted PDF file as bytes
passwordstringThe user or owner password

Returns: Promise<Uint8Array> — The decrypted PDF bytes

Throws:

  • "This PDF is not encrypted" — if the PDF has no encryption dictionary
  • "Incorrect password" — if neither user nor owner password matches
  • "Unsupported encryption" — if the encryption version is not supported

isEncrypted(pdfBytes)

Check if a PDF is encrypted without attempting to decrypt it.

ParameterTypeDescription
pdfBytesUint8ArrayThe PDF file as bytes

Returns: Promise<{ encrypted: boolean, algorithm?: 'AES-256' | 'RC4', version?: number, revision?: number, keyLength?: number }>

Examples

Decrypt with Auto-Detection

import { decryptPDF, isEncrypted } from '@pdfsmaller/pdf-decrypt';

// Check encryption type first
const info = await isEncrypted(pdfBytes);
if (info.encrypted) {
  console.log(`Encrypted with ${info.algorithm}`);
  const decrypted = await decryptPDF(pdfBytes, password);
}

Roundtrip with @pdfsmaller/pdf-encrypt

import { encryptPDF } from '@pdfsmaller/pdf-encrypt';
import { decryptPDF } from '@pdfsmaller/pdf-decrypt';

// Encrypt
const encrypted = await encryptPDF(pdfBytes, 'secret');

// Decrypt
const decrypted = await decryptPDF(encrypted, 'secret');

Browser Usage

<input type="file" id="pdf-input" accept=".pdf" />
<input type="password" id="password" placeholder="Enter password" />
<button id="decrypt-btn">Decrypt</button>

<script type="module">
  import { decryptPDF } from '@pdfsmaller/pdf-decrypt';

  document.getElementById('decrypt-btn').addEventListener('click', async () => {
    const file = document.getElementById('pdf-input').files[0];
    const password = document.getElementById('password').value;
    const pdfBytes = new Uint8Array(await file.arrayBuffer());

    try {
      const decrypted = await decryptPDF(pdfBytes, password);

      // Download
      const blob = new Blob([decrypted], { type: 'application/pdf' });
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = 'decrypted.pdf';
      a.click();
    } catch (e) {
      alert(e.message);
    }
  });
</script>

Supported Encryption

AlgorithmPDF VersionKey LengthStatus
AES-256 (V=5, R=6)2.0 (ISO 32000-2)256-bitSupported
RC4 (V=2, R=3)1.4+ (ISO 32000-1)128-bitSupported
RC4 (V=1, R=2)1.1+40-bitSupported
AES-128 (V=4, R=4)1.6+128-bitNot yet supported

Comparison with pdf-decrypt-lite

Featurepdf-decryptpdf-decrypt-lite
AES-256YesNo
RC4 128-bitYesYes
RC4 40-bitYesYes
Batched asyncYesNo (sync only)
Size~18KB~8KB
Use caseFull decryptionRC4-only, minimal

Choose pdf-decrypt-lite if you only need RC4 and want the smallest possible bundle. Choose pdf-decrypt for full AES-256 + RC4 support.

PackageDescription
@pdfsmaller/pdf-encryptFull encryption — AES-256 + RC4 (companion to this package)
@pdfsmaller/pdf-encrypt-liteLightweight RC4-only encryption (~7KB)
@pdfsmaller/pdf-decrypt-liteLightweight RC4-only decryption (~8KB)

License

MIT — PDFSmaller.com

Keywords

pdf

FAQs

Package last updated on 25 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts