🍋
Menu
Security

PGP

PGP(Pretty Good Privacy)

一种使用对称加密和非对称加密相结合的加密系统,基于去中心化的信任网络模型,为电子邮件、文件和数据提供机密性、认证性和完整性保护。

技术细节

PGP 采用混合加密模式:先用随机对称会话密钥(AES-256)加密数据,然后用接收者的 RSA/ECDH 公钥加密该会话密钥。数字签名使用发送者的私钥对消息的哈希值进行签名。OpenPGP 标准(RFC 4880,由 RFC 9580 更新)由 GnuPG (GPG) 这一开源替代方案实现。密钥管理使用信任网络模型(用户相互为对方的密钥担保),而非集中式证书颁发机构。密钥服务器如 keys.openpgp.org 用于分发公钥。PGP 常用于电子邮件加密、文件加密、软件包签名和 Git 提交签名。

示例

```javascript
// AES-256-GCM encryption (Web Crypto API)
const key = await crypto.subtle.generateKey(
  { name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']
);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt(
  { name: 'AES-GCM', iv },
  key,
  new TextEncoder().encode('secret message')
);
```

相关工具

相关术语