2021-01-30 03:16:53 +00:00
|
|
|
|
# gpg
|
|
|
|
|
|
2021-08-02 09:41:09 +01:00
|
|
|
|
> GNU Privacy Guard.
|
2023-06-30 06:53:15 +01:00
|
|
|
|
> 请参阅 `gpg2` 了解 GNU Privacy Guard 2.
|
2021-10-01 19:28:01 +01:00
|
|
|
|
> 更多信息:<https://gnupg.org>.
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
- 交互地创建 GPG 公钥和私钥:
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
`gpg --full-generate-key`
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
- 不加密,仅对 `doc.txt` 进行签名(生成 `doc.txt.asc`,格式为 ASCII 码形式):
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
`gpg --clearsign {{doc.txt}}`
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
- 为接收者 alice@example.com 和 bob@example.com 签名并加密 `doc.txt`(生成 `doc.txt.gpg`):
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
`gpg --encrypt --sign --recipient {{alice@example.com}} --recipient {{bob@example.com}} {{doc.txt}}`
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
- 只用密码加密 `doc.txt`(生成 `doc.txt.gpg`):
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
|
|
|
|
`gpg --symmetric {{doc.txt}}`
|
|
|
|
|
|
2023-06-30 06:53:15 +01:00
|
|
|
|
- 解密 `doc.txt.gpg`(输出到标准输出):
|
2021-01-30 03:16:53 +00:00
|
|
|
|
|
|
|
|
|
`gpg --decrypt {{doc.txt.gpg}}`
|
|
|
|
|
|
|
|
|
|
- 导入一个公钥:
|
|
|
|
|
|
|
|
|
|
`gpg --import {{public.gpg}}`
|
|
|
|
|
|
|
|
|
|
- 导出 alice@example.com 的公钥(输出到标准输出):
|
|
|
|
|
|
|
|
|
|
`gpg --export --armor {{alice@example.com}}`
|
|
|
|
|
|
|
|
|
|
- 导出 alice@example.com 的私钥(输出到标准输出):
|
|
|
|
|
|
|
|
|
|
`gpg --export-secret-keys --armor {{alice@example.com}}`
|