pdf-encrypt
GitHub

pdf-encrypt

替 PDF 蓋上一枚加密印章。加密、解密、檢視權限與文件屬性,一個命令列工具全包。

安裝 pdf-encrypt

一行裝好

單一執行檔,不需要 Rust、Python 或任何 PDF 函式庫。支援 macOS、Linux、Windows 的 x64 與 ARM64。

組合加密指令
curl -fsSL https://raw.githubusercontent.com/doggy8088/pdf-encrypt/main/install.sh | sh

下載對應平台的執行檔、驗證 SHA-256,再安裝到 ~/.local/bin。指定版本與目錄:| sh -s -- --version 0.3.1 --to ~/bin。

三步蓋好印章

  1. 約 4 秒 安裝:一行指令裝好單一執行檔。
  2. 約 60 秒 組指令:選好密碼、權限與演算法。
  3. 0.52 秒 執行:寫出加密後的 PDF。

安裝與加密為實測:安裝指令稿在一般網路下約 4 秒;61 頁、3.5 MB 的 PDF 以 AES-256 加密 0.52 秒。組指令的時間為估計。

五種常見情境

$ pdf-encrypt encrypt -i report.pdf -p "$PDF_OPEN_PASSWORD"
已完成加密:report_encrypted.pdf
operation: encrypt
algorithm: aes-256
input_encrypted: false
output_encrypted: true
pages: 61
$ pdf-encrypt encrypt -i report.pdf \
    -o report_readonly.pdf \
    --owner-password "$PDF_OWNER_PASSWORD" --read-only
已完成加密:report_readonly.pdf
operation: encrypt
algorithm: aes-256
output_encrypted: true
pages: 61
$ pdf-encrypt decrypt -i report_encrypted.pdf -p "$PDF_PASSWORD"
已完成解密:report_encrypted_decrypted.pdf
operation: decrypt
input_encrypted: true
output_encrypted: false
pages: 61
$ pdf-encrypt info -i annual_encrypted.pdf -p "$PDF_PASSWORD" --json
{
  "document_info": {
    "author": "Will 保哥",
    "keywords": "PDF, 加密",
    "title": "年度報告"
  },
  "input_encrypted": true,
  "pages": 61,
  "pdf_version": "2.0"
}
$ pdf-encrypt encrypt -i report_encrypted.pdf \
    -o report_rekeyed.pdf --algorithm aes-128 \
    --input-open-password "$PDF_PASSWORD" -p "$PDF_OPEN_PASSWORD"
已完成加密:report_rekeyed.pdf
algorithm: aes-128
input_encrypted: true
output_encrypted: true

原檔保留,另存為 report_encrypted.pdf;擁有者密碼自動與開啟密碼相同。

組合你的指令

勾選需要的選項,產生可直接貼到終端機的指令。一切都在瀏覽器裡完成,不會上傳檔案,也不會儲存密碼。

操作
終端機
檔案
密碼

指令會先以不顯示字元的方式詢問密碼並存進環境變數,密碼不會留在 shell 歷史紀錄。

加密與權限

唯讀等於允許全部權限,再禁止修改內容與組合頁面。

文件屬性

勾選要寫入的欄位;勾選但留空會清空該欄位。

輸出格式

一個工具,六件事

每一件都能單獨使用,也能在同一個指令裡一起完成。

演算法與權限

演算法

  • aes-256 預設,新文件建議使用PDF 2.0
  • aes-128 相容較舊的 PDF readerPDF 1.5
  • rc4-128 舊系統相容用途PDF 1.4
  • rc4-40 僅供極舊系統,不建議PDF 1.4

檢視權限

  • 列印文件print
  • 高品質列印high-quality-print
  • 修改內容modify
  • 複製或擷取內容copy
  • 新增或修改註解annotate
  • 填寫表單fill-forms
  • 輔助使用的內容擷取accessibility
  • 組合頁面或大綱assemble

密碼組合

  • 只設開啟密碼:擁有者密碼自動相同,知道密碼的人有完整權限機密
  • 只設擁有者密碼:任何人都能開啟,但 reader 套用權限限制唯讀發布
  • 兩者都設:開啟密碼受限,擁有者密碼享完整權限分級
三張疊放的米色文件,最上面一張蓋著朱紅色的方形印章,印章中央是鑰匙孔,旁邊放著一支木柄印章。

常見問題

不能。PDF 權限是 reader 應遵守的限制,不是無法破解的存取控制。真正保護內容機密的是加密後的開啟密碼,請使用夠長、不易猜測的密碼。

不會。網站只在瀏覽器裡產生指令文字,實際的加密與解密都由你電腦上的 pdf-encrypt 執行。

不能。decrypt 需要正確的開啟密碼或擁有者密碼。只有權限限制、沒有開啟密碼的 PDF,可以省略 --password 直接解密。

預設不會。未指定輸出時另存為 <原檔名>_encrypted.pdf 等新檔;只有加上 --in-place,才會在寫入成功後取代原檔。

macOS(Apple 晶片與 Intel)、Linux(x64 與 ARM64,glibc 與 musl 皆可)、Windows(x64 與 ARM64)。npm 與安裝指令稿會自動選擇對應的執行檔。