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

@pdfsmaller/pdf-encrypt

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-encrypt

Full-featured PDF encryption with AES-256 and RC4 128-bit support. Built for browsers, Node.js, and edge environments. Powers PDFSmaller.com's encryption.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

@pdfsmaller/pdf-encrypt

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

Powers PDFSmaller.com's Protect PDF tool.

Features

  • AES-256 encryption (V=5, R=6) — PDF 2.0 standard, maximum security
  • RC4 128-bit encryption (V=2, R=3) — legacy compatibility mode
  • Granular permissions — control printing, copying, modifying, and more
  • User + Owner passwords — separate passwords for opening and managing PDFs
  • Web Crypto API — no native dependencies, works everywhere
  • Lightweight — ~15KB total (crypto + encryption logic)
  • Zero dependencies — only pdf-lib as a peer dependency
  • TypeScript types included

Installation

npm install @pdfsmaller/pdf-encrypt pdf-lib

Quick Start

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

const pdfBytes = fs.readFileSync('input.pdf');

// AES-256 encryption (default, recommended)
const encrypted = await encryptPDF(new Uint8Array(pdfBytes), 'my-password');
fs.writeFileSync('encrypted.pdf', encrypted);

API

encryptPDF(pdfBytes, userPassword, options?)

ParameterTypeDescription
pdfBytesUint8ArrayThe PDF file as bytes
userPasswordstringPassword required to open the PDF
optionsobjectOptional configuration (see below)

Returns: Promise<Uint8Array> — The encrypted PDF bytes

Options

OptionTypeDefaultDescription
ownerPasswordstringsame as userPassword for managing permissions
algorithm'AES-256' | 'RC4''AES-256'Encryption algorithm
allowPrintingbooleantrueAllow printing the document
allowModifyingbooleantrueAllow modifying content
allowCopyingbooleantrueAllow copying text/images
allowAnnotatingbooleantrueAllow adding annotations
allowFillingFormsbooleantrueAllow form filling
allowExtractionbooleantrueAllow accessibility extraction
allowAssemblybooleantrueAllow document assembly
allowHighQualityPrintbooleantrueAllow high-quality printing

Examples

Restrict Permissions

const encrypted = await encryptPDF(pdfBytes, 'user-pass', {
  ownerPassword: 'admin-pass',
  allowPrinting: true,
  allowCopying: false,
  allowModifying: false
});

RC4 Legacy Mode

const encrypted = await encryptPDF(pdfBytes, 'password', {
  algorithm: 'RC4'
});

Browser Usage

<input type="file" id="pdf-input" accept=".pdf" />
<script type="module">
  import { encryptPDF } from '@pdfsmaller/pdf-encrypt';

  document.getElementById('pdf-input').addEventListener('change', async (e) => {
    const file = e.target.files[0];
    const pdfBytes = new Uint8Array(await file.arrayBuffer());
    const encrypted = await encryptPDF(pdfBytes, 'secret');

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

AES-256 vs RC4

FeatureAES-256RC4
SecurityQuantum-resistantDeprecated, known weaknesses
PDF Version2.0 (ISO 32000-2)1.4+ (ISO 32000-1)
Key Length256-bit128-bit
Reader SupportModern readersAll readers
RecommendedYesLegacy only
PackageDescription
@pdfsmaller/pdf-decryptFull decryption — 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