2025-03-14 21:59:59 -06:00
|
|
|
|
# gpg
|
|
|
|
|
|
|
|
|
|
|
|
> GNU Privacy Guard.
|
2025-04-03 20:36:56 -06:00
|
|
|
|
> 更多信息:<https://gnupg.org/documentation/manuals/gnupg/Invoking-GPG.html>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- 交互地创建 GPG 公钥和私钥:
|
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
|
`gpg {{[--full-gen-key|--full-generate-key]}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- 不加密,仅对 `doc.txt` 进行签名(生成 `doc.txt.asc`,格式为 ASCII 码形式):
|
|
|
|
|
|
|
|
|
|
|
|
`gpg --clearsign {{doc.txt}}`
|
|
|
|
|
|
|
|
|
|
|
|
- 为接收者 alice@example.com 和 bob@example.com 签名并加密 `doc.txt`(生成 `doc.txt.gpg`):
|
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
|
`gpg {{[-es|--encrypt --sign]}} {{[-r|--recipient]}} {{alice@example.com}} {{[-r|--recipient]}} {{bob@example.com}} {{doc.txt}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- 只用密码加密 `doc.txt`(生成 `doc.txt.gpg`):
|
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
|
`gpg {{[-c|--symmetric]}} {{doc.txt}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- 解密 `doc.txt.gpg`(输出到标准输出):
|
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
|
`gpg {{[-d|--decrypt]}} {{doc.txt.gpg}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- 导入一个公钥:
|
|
|
|
|
|
|
|
|
|
|
|
`gpg --import {{public.gpg}}`
|
|
|
|
|
|
|
|
|
|
|
|
- 导出 alice@example.com 的公钥(输出到标准输出):
|
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
|
`gpg --export {{[-a|--armor]}} {{alice@example.com}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- 导出 alice@example.com 的私钥(输出到标准输出):
|
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
|
`gpg --export-secret-keys {{[-a|--armor]}} {{alice@example.com}}`
|