zh

PGP加密完整教程:保护邮件和文件的最强加密方案

PGP(Pretty Good Privacy)是目前应用最广泛的邮件和文件加密标准,经过30年以上的使用和安全审计。无论是记者保护信源,还是普通用户保护商业机密,PGP提供了端对端加密保证。本教程从生成密钥到实际使用,提供完整的中文操作指南。

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

PGP基础原理

PGP使用非对称加密:每个用户有一对密钥——公钥和私钥。

  • 公钥:可以公开分享,任何人都可以用公钥加密发给你的邮件
  • 私钥:必须保密,只有私钥才能解密用你公钥加密的内容

加密流程:发件人用你的公钥加密邮件 -> 密文在网络上传输 -> 你用私钥解密 -> 读取原文

即使邮件服务器被攻击或监听,攻击者看到的也只是无法解密的密文(除非他们有你的私钥)。

签名:用私钥对文件签名,接收方用你的公钥验证签名确实来自你(防止伪造)。这是验证软件下载包真实性的标准方法(如Tor浏览器、Tails OS都提供PGP签名)。

安装GPG并生成密钥对

安装GPG:

  • Linux:sudo apt install gnupg(大多数发行版预装)
  • macOS:brew install gnupg 或 从 gpgtools.org 下载 GPG Suite
  • Windows:从 gpg4win.org 下载 Gpg4win

生成密钥对:

gpg --full-generate-key

选择选项:

  1. 密钥类型:选择 9(ECC,椭圆曲线,比RSA更安全)
  2. 椭圆曲线:选择 1(Curve 25519)
  3. 有效期:建议2年(过期提醒你更新密钥)
  4. 输入姓名(可以用假名)和邮箱
  5. 设置一个强密码保护私钥

导出公钥(与他人分享):

gpg --armor --export your@email.com > my_public_key.asc

使用GPG加密和解密

加密文件给接收方(使用他们的公钥):

# 首先导入接收方公钥
gpg --import recipient_public_key.asc

# 加密文件
gpg --encrypt --recipient recipient@email.com secret_document.txt

生成 secret_document.txt.gpg(加密文件)

解密文件(使用自己的私钥):

gpg --decrypt secret_document.txt.gpg > decrypted.txt

系统会提示输入你的私钥密码。

同时加密并签名:

gpg --encrypt --sign --recipient recipient@email.com document.txt

验证签名:

gpg --verify document.txt.sig document.txt

Thunderbird邮件客户端集成

Thunderbird(78版以后)原生支持OpenPGP加密,不再需要Enigmail插件:

  1. 安装Thunderbird并配置邮箱账户(ProtonMail、Riseup等隐私邮箱)
  2. Account Settings -> End-to-End Encryption
  3. 点击「Add Key」-> 导入现有GPG密钥,或在Thunderbird内生成新密钥
  4. 配置完成后,写邮件时出现加密和签名按钮

ProtonMail用户注意:ProtonMail的网页版内置PGP支持,不需要Thunderbird。如果你的通讯对象也使用ProtonMail,邮件自动加密(无需手动配置GPG)。如果对方使用普通邮箱(Gmail等),可以在ProtonMail设置中为其外部公钥,发送加密邮件。

密钥管理最佳实践

备份私钥(极重要):

gpg --armor --export-secret-key your@email.com > private_key_backup.asc

将备份文件存储在加密的USB驱动器或KeePassXC数据库中,放在安全的物理位置。私钥丢失意味着无法解密之前用公钥加密的所有内容。

生成吊销证书(备用):

gpg --gen-revoke your@email.com > revoke.asc

如果私钥丢失或被盗,上传吊销证书到密钥服务器,告知他人你的公钥已失效。

发布公钥到密钥服务器:

gpg --send-keys --keyserver keys.openpgp.org YOUR_KEY_ID

这样其他人可以通过搜索你的邮箱找到并导入你的公钥,无需手动分享公钥文件。

Why Anubiz Host

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

Ready to get started?

Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.

Anubiz Chat AI

Online