npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pdfsmaller/pdf-encrypt-lite

v1.0.1

Published

Ultra-lightweight PDF encryption (7KB) with real RC4 128-bit encryption. Built for edge environments like Cloudflare Workers. Powers PDFSmaller.com's encryption.

Readme

pdf-encrypt-lite 🔒

Ultra-lightweight PDF encryption library (only 7KB!) with real RC4 128-bit encryption

Built by PDFSmaller.com - Try our free online PDF tools with this encryption built-in!

NPM Version Size License Powered by PDFSmaller

🚀 Why pdf-encrypt-lite?

When building PDFSmaller.com, we needed real PDF encryption that worked within Cloudflare Workers' 1MB limit. Every existing solution was 2-20MB+ in size. We were told it was "impossible" to implement proper PDF encryption in such a small package.

We proved them wrong.

This library is the exact encryption engine that powers PDFSmaller.com's Protect PDF tool - battle-tested on thousands of PDFs daily.

The Problem We Solved:

  • node-forge: 1.7MB minified
  • crypto-js: 234KB (still too large with pdf-lib)
  • Native crypto: Not available in many edge environments
  • pdf-encrypt-lite: Only 7KB! 🎉

✨ Features

  • 🔐 Real PDF encryption - RC4 128-bit encryption that actually works
  • 📦 Tiny size - Only ~7KB total (MD5 + RC4 implementations)
  • Edge-ready - Works in Cloudflare Workers, Vercel Edge, Deno Deploy
  • 🌐 Browser compatible - No Node.js dependencies
  • 📱 Password protection - PDFs prompt for password in any reader
  • 🛡️ PDF Standard compliant - Implements Algorithm 2 & 3 from PDF spec
  • 🚀 Zero dependencies - Just needs pdf-lib as peer dependency

📥 Installation

npm install @pdfsmaller/pdf-encrypt-lite pdf-lib

💻 Usage

import { encryptPDF } from '@pdfsmaller/pdf-encrypt-lite';
import { PDFDocument } from 'pdf-lib';

// Basic usage
const encryptedPdfBytes = await encryptPDF(existingPdfBytes, 'user-password');

// With separate owner password
const encryptedPdfBytes = await encryptPDF(
  existingPdfBytes, 
  'user-password',
  'owner-password'
);

// Full example
async function protectPDF() {
  // Load your PDF
  const existingPdfBytes = await fetch('document.pdf').then(res => res.arrayBuffer());
  
  // Encrypt it with pdf-encrypt-lite
  const encryptedBytes = await encryptPDF(
    new Uint8Array(existingPdfBytes),
    'secret123',
    'owner456'
  );
  
  // Save the encrypted PDF
  const blob = new Blob([encryptedBytes], { type: 'application/pdf' });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = 'protected.pdf';
  a.click();
}

🔥 Use Cases

Perfect for:

  • Edge Functions (Cloudflare Workers, Vercel Edge, Netlify Edge)
  • Browser applications (Like PDFSmaller.com)
  • Serverless functions with size limits
  • Client-side PDF protection without server uploads
  • Lightweight Node.js applications

🎯 Real-World Example

See it in action at PDFSmaller.com/protect-pdf - our free online tool uses this exact library to encrypt PDFs directly in your browser. No uploads, no server processing, just pure client-side encryption!

🏗️ How It Works

We built custom implementations of:

  1. MD5 hashing - For password processing per PDF spec
  2. RC4 encryption - For content encryption
  3. PDF object traversal - Encrypts all strings and streams
  4. Standard Security Handler - Implements PDF encryption spec

Total size: ~7KB 🤯

📊 Comparison

| Library | Size | Real Encryption | Edge Compatible | |---------|------|-----------------|-----------------| | pdf-encrypt-lite | 7KB ✅ | ✅ | ✅ | | node-forge | 1,700KB | ✅ | ❌ | | crypto-js | 234KB | ✅ | ⚠️ | | pdf-lib alone | 0KB | ❌ | ✅ |

🤝 Contributing

We welcome contributions! This library powers PDFSmaller.com, so we maintain high standards for security and compatibility.

📜 License

MIT License - Use it freely in your projects!

🙏 Credits

Built with ❤️ by PDFSmaller.com - Your free PDF toolkit

If this library helps you, check out our other free PDF tools:

🚀 Quick Start for Cloudflare Workers

export default {
  async fetch(request, env) {
    const formData = await request.formData();
    const file = formData.get('pdf');
    const password = formData.get('password');
    
    const pdfBytes = new Uint8Array(await file.arrayBuffer());
    const encrypted = await encryptPDF(pdfBytes, password);
    
    return new Response(encrypted, {
      headers: { 'Content-Type': 'application/pdf' }
    });
  }
}

📧 Support


⭐ Star this repo if it helps you!

Built because we needed it. Shared because you might too.

PDFSmaller.com - Free PDF Tools That Actually Work™