GPG 使用介绍

发布时间: 更新时间: 总字数:1101 阅读时间:3m 作者: IP上海 分享 网址

GPG(GNU Privacy Guard)是一种基于Open PGP标准的加密方式,本文介绍如何安装和使用GPG。

什么是 GPG

  • PGP(Pretty Good Privacy) 是一种常用的加密方式,在 1991 年由 Phil Zimmermann 开发,现在归属于 Symantec 公司,付费商业软件

安装客户端工具

Mac安装GPG

brew install gpg
或
brew cask install keybase

Win安装GnuPG

  • 我安装的是Gpg4win(下载地址),安装信息如下:
$ gpg --version
gpg (GnuPG) 1.4.20
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

在一些系统中会使用gpg2(其实window 7并没有使用),信息如下:

$ gpg2 --version
gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)
libgcrypt 1.6.6
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: C:/Users/Administrator/AppData/Roaming/gnupg
Supported algorithms:
Pubkey: RSA, RSA, RSA, ELG, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

使用

我们可以自己生成 GPG key 并使用,也可以采用 keybase 生成的 GPG Key

常用命令

$ gpg --gen-key
$ gpg --list-keys
$ gpg --list-secret-keys
$ gpg2 --list-keys
$ gpg2 --list-secret-keys

$ gpg2 --keyserver hkp://pool.sks-keyservers.net --send-keys C6EED57A
$ gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys C6EED57A

生成 GPG key

gpg --gen-key

具体步骤如下:

~ xiexianbin$ gpg --gen-key
gpg (GnuPG) 2.2.15; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

注意:使用 “gpg --full-generate-key” 以获得一个功能完整的密钥产生对话框。

GnuPG 需要构建用户标识以辨认您的密钥。

真实姓名: xiexianbin
电子邮件地址: me@xiexianbin.cn
您选定了此用户标识:
    “xiexianbin <me@xiexianbin.cn>”

更改姓名(N)、注释(C)、电子邮件地址(E)或确定(O)/退出(Q)? o
我们需要生成大量的随机字节。在质数生成期间做些其他操作(敲打键盘
、移动鼠标、读写硬盘之类的)将会是一个不错的主意;这会让随机数
发生器有更好的机会获得足够的熵。
gpg: 密钥 8284896418BCC645 被标记为绝对信任
gpg: 目录‘/Users/xiexianbin/.gnupg/openpgp-revocs.d’已创建
gpg: 吊销证书已被存储为‘/Users/xiexianbin/.gnupg/openpgp-revocs.d/11518af49eaa27d86ea01b5c901487ea218aeb1a.rev’
公钥和私钥已经生成并被签名。

pub   rsa2048 2019-05-16 [SC] [有效至:2021-05-15]
      11518af49eaa27d86ea01b5c901487ea218aeb1a
uid                      xiexianbin <me@xiexianbin.cn>
sub   rsa2048 2019-05-16 [E] [有效至:2021-05-15]

查看GPG key

gpg --list-keys
gpg --list-secret-keys

示例:

~ xiexianbin$ gpg --list-keys
/Users/xiexianbin/.gnupg/pubring.kbx
------------------------------------
pub   rsa2048 2019-05-16 [SC] [有效至:2021-05-15]
      11518af49eaa27d86ea01b5c901487ea218aeb1a
uid           [ 绝对 ] xiexianbin <me@xiexianbin.cn>
sub   rsa2048 2019-05-16 [E] [有效至:2021-05-15]

~ xiexianbin$

注意:

  • pub:公钥
  • sub:私钥
  • 11518af49eaa27d86ea01b5c901487ea218aeb1apub GPG key ID

导出公钥

gpg --armor --export <pub GPG key ID>

示例:

~ xiexianbin$ gpg --armor --export 11518af49eaa27d86ea01b5c901487ea218aeb1a
-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

GPG key 格式:

-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

删除GPG key

gpg --delete-keys <pub GPG key ID>
gpg --delete-secret-keys <pub GPG key ID>

常见的 keyserver 服务器

参考

  1. https://en.wikipedia.org/wiki/Pretty_Good_Privacy
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数