{"_id":"@pdfsmaller/pdf-encrypt","_rev":"4-50439068cca8ffaedaf8b06b06077c41","name":"@pdfsmaller/pdf-encrypt","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@pdfsmaller/pdf-encrypt","version":"1.0.0","keywords":["pdf","encryption","pdf-encryption","AES-256","AES","RC4","128-bit","256-bit","password-protection","pdf-security","cloudflare","edge","workers","browser","pdf-lib","pdfsmaller"],"author":{"url":"https://pdfsmaller.com","name":"PDFSmaller.com","email":"hello@pdfsmaller.com"},"license":"MIT","_id":"@pdfsmaller/pdf-encrypt@1.0.0","maintainers":[{"name":"smither777","email":"ericpaolosmith@gmail.com"}],"homepage":"https://pdfsmaller.com","bugs":{"url":"https://github.com/smither777/pdf-encrypt/issues"},"dist":{"shasum":"8ac3a71c8921e5b8deb7a799784bf9e8a5090d10","tarball":"https://registry.npmjs.org/@pdfsmaller/pdf-encrypt/-/pdf-encrypt-1.0.0.tgz","fileCount":12,"integrity":"sha512-XPxifJjKeGdxoIbAdoeHzU5c2db/UFDF5ZamrDrZArLgZfsxYR4K7Hvpoed+WUeWIZX+KmF9AhH9b9nbKiMzpw==","signatures":[{"sig":"MEUCIQDKCue5pIdYe5Z4yJ50g4turhj2pdLQB9/YFQULdr4niAIgCu90Mw52MEocGRfiVky51cWr1yC2/FVhCnlbCzfIjx8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":72664},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"d21310f5e1563194e852cacdd60f52fda7f98807","scripts":{"test":"node test.js","build":"node build.js","prepublishOnly":"npm run build"},"_npmUser":{"name":"smither777","email":"ericpaolosmith@gmail.com"},"repository":{"url":"git+https://github.com/smither777/pdf-encrypt.git","type":"git"},"_npmVersion":"11.8.0","description":"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.","directories":{},"_nodeVersion":"24.7.0","_hasShrinkwrap":false,"devDependencies":{"pdf-lib":"^1.17.1"},"peerDependencies":{"pdf-lib":"^1.17.1"},"_npmOperationalInternal":{"tmp":"tmp/pdf-encrypt_1.0.0_1772011745340_0.25581026703881515","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@pdfsmaller/pdf-encrypt","version":"1.0.2","keywords":["pdf","encryption","pdf-encryption","AES-256","AES","RC4","128-bit","256-bit","password-protection","pdf-security","cloudflare","edge","workers","browser","pdf-lib","pdfsmaller"],"author":{"url":"https://pdfsmaller.com","name":"PDFSmaller.com","email":"hello@pdfsmaller.com"},"license":"MIT","_id":"@pdfsmaller/pdf-encrypt@1.0.2","maintainers":[{"name":"smither777","email":"ericpaolosmith@gmail.com"}],"homepage":"https://pdfsmaller.com","bugs":{"url":"https://github.com/smither777/pdf-encrypt/issues"},"dist":{"shasum":"57bed03c3b66a6f78d8c3e5b1323edefc09ba4be","tarball":"https://registry.npmjs.org/@pdfsmaller/pdf-encrypt/-/pdf-encrypt-1.0.2.tgz","fileCount":12,"integrity":"sha512-F+gEftljSsEV3Zh+6XY0Q7garrRJlVMgomqGJDC+L5RIFpHyMZ0pQX0RPoN3JXn25BGd13T/62b6W3+mrxOkTw==","signatures":[{"sig":"MEUCIQClkajQrY6qzL2s/Mi7DLqT1jU6Yn3YxkStMUaQIql6ZQIgHQ4dOMJsFiUKmNoLAp8cQ7JiB9k3tNvomqMDYmmgmG0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":72889},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"9e66b653a18251b7ad59a7e6a9671361bb712324","scripts":{"test":"node test.js","build":"node build.js","prepublishOnly":"npm run build"},"_npmUser":{"name":"smither777","email":"ericpaolosmith@gmail.com"},"repository":{"url":"git+https://github.com/smither777/pdf-encrypt.git","type":"git"},"_npmVersion":"11.8.0","description":"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.","directories":{},"_nodeVersion":"24.7.0","_hasShrinkwrap":false,"devDependencies":{"pdf-lib":"^1.17.1"},"peerDependencies":{"pdf-lib":"^1.17.1"},"_npmOperationalInternal":{"tmp":"tmp/pdf-encrypt_1.0.2_1772014790403_0.233939651491609","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@pdfsmaller/pdf-encrypt","version":"1.1.0","keywords":["pdf","encryption","pdf-encryption","AES-256","AES","RC4","128-bit","256-bit","password-protection","pdf-security","cloudflare","edge","workers","browser","pdf-lib","pdfsmaller"],"author":{"url":"https://pdfsmaller.com","name":"PDFSmaller.com","email":"hello@pdfsmaller.com"},"license":"MIT","_id":"@pdfsmaller/pdf-encrypt@1.1.0","maintainers":[{"name":"smither777","email":"ericpaolosmith@gmail.com"}],"homepage":"https://pdfsmaller.com","bugs":{"url":"https://github.com/smither777/pdf-encrypt/issues"},"dist":{"shasum":"6cdd409e49d202804b0daaf9b29ea4ce72d9a1c4","tarball":"https://registry.npmjs.org/@pdfsmaller/pdf-encrypt/-/pdf-encrypt-1.1.0.tgz","fileCount":15,"integrity":"sha512-RDX8DCcVAHIDfW3CqTR2IAqemPZvo6ZBq+AGrks8JneyQG0mmzXz/dD8sul8Ugk38et41oMB9Ep8vkq15Us0Ww==","signatures":[{"sig":"MEUCIQC6V3jm5WeGQrbxyCk4hSvjqOUaYv3Kw7N5OpetsVjyDAIgR85n7Q5byedAYcRlHUEWRbOCTCVQhxZpfGhFMNpcECU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":126718},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"e40ce6165c6f24d3f6b7dcd59981d34a02e8c642","scripts":{"test":"node test.js","build":"node build.js","prepublishOnly":"npm run build"},"_npmUser":{"name":"smither777","email":"ericpaolosmith@gmail.com"},"repository":{"url":"git+https://github.com/smither777/pdf-encrypt.git","type":"git"},"_npmVersion":"11.13.0","description":"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.","directories":{},"_nodeVersion":"24.17.0","_hasShrinkwrap":false,"devDependencies":{"pdf-lib":"^1.17.1"},"peerDependencies":{"pdf-lib":"^1.17.1"},"_npmOperationalInternal":{"tmp":"tmp/pdf-encrypt_1.1.0_1785250266689_0.9023424063784942","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@pdfsmaller/pdf-encrypt","version":"1.2.0","description":"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.","type":"commonjs","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"node build.js","test":"node test.js","prepublishOnly":"npm run build"},"keywords":["pdf","encryption","pdf-encryption","AES-256","AES","RC4","128-bit","256-bit","password-protection","pdf-security","cloudflare","edge","workers","browser","pdf-lib","pdfsmaller"],"author":{"name":"PDFSmaller.com","email":"hello@pdfsmaller.com","url":"https://pdfsmaller.com"},"homepage":"https://pdfsmaller.com","repository":{"type":"git","url":"git+https://github.com/smither777/pdf-encrypt.git"},"bugs":{"url":"https://github.com/smither777/pdf-encrypt/issues"},"license":"MIT","engines":{"node":">=18.0.0"},"peerDependencies":{"pdf-lib":"^1.17.1"},"devDependencies":{"pdf-lib":"^1.17.1"},"gitHead":"2b085fafdc240e85827fd3ef552faa3595d66e4a","_id":"@pdfsmaller/pdf-encrypt@1.2.0","_nodeVersion":"24.17.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-fIS3Ld+hOpoxmwmgoAnPjVC+9CN6/wbineumJ9ZOlJXZcuXft8OvdcSGqUDCpRSVJilrhYHsnJg626j06eM85g==","shasum":"6e97b67b3de02944c4b7b7a1f88c246dff17dac3","tarball":"https://registry.npmjs.org/@pdfsmaller/pdf-encrypt/-/pdf-encrypt-1.2.0.tgz","fileCount":16,"unpackedSize":188947,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHrQkzS/kFiXFWqPxdZhTqTpPjHXytZNpYWJ7sWJ2PQTAiAYynHO0zGHjUcHo/KFTiKKvr7R70eNHV5USlMGI8CExw=="}]},"_npmUser":{"name":"smither777","email":"ericpaolosmith@gmail.com"},"directories":{},"maintainers":[{"name":"smither777","email":"ericpaolosmith@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pdf-encrypt_1.2.0_1785251340358_0.47590160370076906"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-25T09:29:05.266Z","modified":"2026-07-28T15:09:00.749Z","1.0.0":"2026-02-25T09:29:05.472Z","1.0.2":"2026-02-25T10:19:50.559Z","1.1.0":"2026-07-28T14:51:06.838Z","1.2.0":"2026-07-28T15:09:00.520Z"},"bugs":{"url":"https://github.com/smither777/pdf-encrypt/issues"},"author":{"name":"PDFSmaller.com","email":"hello@pdfsmaller.com","url":"https://pdfsmaller.com"},"license":"MIT","homepage":"https://pdfsmaller.com","keywords":["pdf","encryption","pdf-encryption","AES-256","AES","RC4","128-bit","256-bit","password-protection","pdf-security","cloudflare","edge","workers","browser","pdf-lib","pdfsmaller"],"repository":{"type":"git","url":"git+https://github.com/smither777/pdf-encrypt.git"},"description":"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.","maintainers":[{"name":"smither777","email":"ericpaolosmith@gmail.com"}],"readme":"# @pdfsmaller/pdf-encrypt\n\nFull-featured PDF encryption with **AES-256** and **RC4 128-bit** support. Built for browsers, Node.js 18+, Cloudflare Workers, and Deno.\n\nPowers [PDFSmaller.com](https://pdfsmaller.com)'s [Protect PDF](https://pdfsmaller.com/protect-pdf) tool.\n\n> **⚠️ Upgrade to 1.1.0.** Versions 1.0.x wrote encrypted strings into PDF\n> literal strings without escaping them, which corrupted any PDF containing\n> literal strings — form field names, JavaScript actions, metadata. Fields went\n> missing and calculations stopped working, differently on every run. See\n> [CHANGELOG.md](CHANGELOG.md).\n\n## Features\n\n- **AES-256 encryption** (V=5, R=6) — PDF 2.0 standard, maximum security\n- **RC4 128-bit encryption** (V=2, R=3) — legacy compatibility mode\n- **Granular permissions** — control printing, copying, modifying, and more\n- **User + Owner passwords** — separate passwords for opening and managing PDFs\n- **Web Crypto API** — no native dependencies, works everywhere\n- **Lightweight** — ~17KB gzipped (crypto + encryption + password encoding)\n- **Zero dependencies** — only `pdf-lib` as a peer dependency\n- **TypeScript types** included\n\n## Installation\n\n```bash\nnpm install @pdfsmaller/pdf-encrypt pdf-lib\n```\n\n## Quick Start\n\n```javascript\nimport { encryptPDF } from '@pdfsmaller/pdf-encrypt';\nimport fs from 'fs';\n\nconst pdfBytes = fs.readFileSync('input.pdf');\n\n// AES-256 encryption (default, recommended)\nconst encrypted = await encryptPDF(new Uint8Array(pdfBytes), 'my-password');\nfs.writeFileSync('encrypted.pdf', encrypted);\n```\n\n## Browser (no bundler)\n\nFor environments with no build step — SharePoint script editors, classic ASP.NET\npages, plain HTML — use the UMD build. It reads pdf-lib from the global that\n`pdf-lib.min.js` installs, so load that first:\n\n```html\n<script src=\"pdf-lib.min.js\"></script>\n<script src=\"node_modules/@pdfsmaller/pdf-encrypt/dist/pdf-encrypt.umd.js\"></script>\n<script>\n  (async () => {\n    const bytes = new Uint8Array(await (await fetch('form.pdf')).arrayBuffer());\n\n    // Pre-fill with pdf-lib as usual…\n    const doc = await PDFLib.PDFDocument.load(bytes);\n    doc.getForm().getTextField('Name').setText('Marco Foerster');\n    const filled = await doc.save();\n\n    // …then apply permissions. Empty user password = opens with no prompt.\n    const protectedPdf = await PDFEncrypt.encryptPDF(filled, '', {\n      ownerPassword: 'owner-secret',\n      allowPrinting: true,\n      allowFillingForms: true,   // also covers signing an existing signature field\n      allowModifying: false,\n      allowCopying: false,\n    });\n  })();\n</script>\n```\n\n`PDFEncrypt` is the global; everything the package exports is on it.\n\n> **Secure context required for AES-256.** `crypto.subtle` is only exposed over\n> HTTPS or on localhost. If your site is served over plain HTTP, AES-256 will\n> fail — pass `{ algorithm: 'RC4' }`, which does not use `crypto.subtle`.\n> RC4 still needs `crypto.getRandomValues()` to generate a file ID when the\n> source PDF has none; browsers expose that in non-secure contexts, so this\n> works over HTTP, but it is not a no-Web-Crypto-at-all fallback.\n> Note that RC4 is cryptographically weak; it is fine for declaring\n> permissions, not for confidentiality.\n\n### Permissions without an open password\n\nPassing an empty string as the user password produces a PDF that opens without\nprompting but still declares its permissions; conforming readers require the\nowner password to change them:\n\n```js\nawait PDFEncrypt.encryptPDF(pdfBytes, '', { ownerPassword: 'owner-secret', allowPrinting: true });\n```\n\nBe aware that PDF permissions are advisory: conforming readers honour them, but\nnothing cryptographically prevents a determined tool from ignoring them. Use a\nuser password if the content itself must stay confidential.\n\n## API\n\n### `encryptPDF(pdfBytes, userPassword, options?)`\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `pdfBytes` | `Uint8Array` | The PDF file as bytes |\n| `userPassword` | `string` | Password required to open the PDF |\n| `options` | `object` | Optional configuration (see below) |\n\n**Returns:** `Promise<Uint8Array>` — The encrypted PDF bytes\n\n### Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `ownerPassword` | `string` | same as user | Password for managing permissions |\n| `algorithm` | `'AES-256' \\| 'RC4'` | `'AES-256'` | Encryption algorithm |\n| `allowPrinting` | `boolean` | `true` | Allow printing the document |\n| `allowModifying` | `boolean` | `true` | Allow modifying content |\n| `allowCopying` | `boolean` | `true` | Allow copying text/images |\n| `allowAnnotating` | `boolean` | `true` | Allow adding annotations |\n| `allowFillingForms` | `boolean` | `true` | Allow filling existing form fields, including signing an existing signature field (ISO 32000-2 Table 22, bit 9 — applies even when `allowAnnotating` is false) |\n| `allowExtraction` | `boolean` | `true` | Allow accessibility extraction |\n| `allowAssembly` | `boolean` | `true` | Allow document assembly |\n| `allowHighQualityPrint` | `boolean` | `true` | Allow high-quality printing |\n\n## Examples\n\n### Restrict Permissions\n\n```javascript\nconst encrypted = await encryptPDF(pdfBytes, 'user-pass', {\n  ownerPassword: 'admin-pass',\n  allowPrinting: true,\n  allowCopying: false,\n  allowModifying: false\n});\n```\n\n### RC4 Legacy Mode\n\n```javascript\nconst encrypted = await encryptPDF(pdfBytes, 'password', {\n  algorithm: 'RC4'\n});\n```\n\n### Browser Usage\n\n```html\n<input type=\"file\" id=\"pdf-input\" accept=\".pdf\" />\n<script type=\"module\">\n  import { encryptPDF } from '@pdfsmaller/pdf-encrypt';\n\n  document.getElementById('pdf-input').addEventListener('change', async (e) => {\n    const file = e.target.files[0];\n    const pdfBytes = new Uint8Array(await file.arrayBuffer());\n    const encrypted = await encryptPDF(pdfBytes, 'secret');\n\n    // Download\n    const blob = new Blob([encrypted], { type: 'application/pdf' });\n    const url = URL.createObjectURL(blob);\n    const a = document.createElement('a');\n    a.href = url;\n    a.download = 'encrypted.pdf';\n    a.click();\n  });\n</script>\n```\n\n## AES-256 vs RC4\n\n| Feature | AES-256 | RC4 |\n|---------|---------|-----|\n| Security | Quantum-resistant | Deprecated, known weaknesses |\n| PDF Version | 2.0 (ISO 32000-2) | 1.4+ (ISO 32000-1) |\n| Key Length | 256-bit | 128-bit |\n| Reader Support | Modern readers | All readers |\n| Recommended | Yes | Legacy only |\n\n## Related Packages\n\n| Package | Description |\n|---------|-------------|\n| [@pdfsmaller/pdf-decrypt](https://www.npmjs.com/package/@pdfsmaller/pdf-decrypt) | Full decryption — AES-256 + RC4 (companion to this package) |\n| [@pdfsmaller/pdf-encrypt-lite](https://www.npmjs.com/package/@pdfsmaller/pdf-encrypt-lite) | Lightweight RC4-only encryption (~9KB gzipped) |\n| [@pdfsmaller/pdf-decrypt-lite](https://www.npmjs.com/package/@pdfsmaller/pdf-decrypt-lite) | Lightweight RC4-only decryption (~8KB) |\n\n## License\n\nMIT — [PDFSmaller.com](https://pdfsmaller.com)\n","readmeFilename":"README.md"}