慈浩艺的主页

This page uses UTF-8 character set, please make sure your browser supports it

PGP 和 GPG 使用技巧

创建时间: Sun May 15 2022 16:34:57 GMT+0800
修改时间: Tue Jun 07 2022 15:01:04 GMT+0800

在本页面,我将记录一些 PGP 和 GnuPG 的使用技巧,以供个人使用。

使用方法

在本节,我们将集中讨论 GnuPG 在命令行中的使用方法。

生成新的密钥对

gpg --gen-key               # 生成新的密钥对
gpg --generate-key          # 与 "--gen-key" 相同
gpg --full-gen-key          # 全特性的密钥对生成
gpg --full-generate-key     # 与 "--full-gen-key" 相同
gpg --full-gen-key --expert # 在专家模式的全特性生成。包含最多的选项!

在本节剩余部分中,我将基于"--full-gen-key --expert"

你将得到如下结果

$ gpg --full-gen-key --expert
gpg (GnuPG) 2.2.31; Copyright (C) 2021 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.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
   (9) ECC and ECC
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (13) Existing key
  (14) Existing key from card
Your selection?

你可以在这里选择一个预设来生成你的密钥对。这里有一些“非对称加密算法”可供选择,他们是 DSA, RSA, ECC 和 Elgamal。DSA太旧了,以至于它不再安全。我不了解Elgamal,但看起来这不是大多数人的选择。 RSA 和 ECC 被广泛使用。 RSA 基于大质数分解难题,它已经经历了很长时间了,所以更加成熟。 ECC 基于椭圆曲线数学,是一种新的方法,所以在旧的机器上不会被支持。但是在相同密钥长度下, ECC 比 RSA 有更强的安全性。

如果你选择"ECC and ECC", 你将得到

Please select which elliptic curve you want:
   (1) Curve 25519
   (3) NIST P-256
   (4) NIST P-384
   (5) NIST P-521
   (6) Brainpool P-256
   (7) Brainpool P-384
   (8) Brainpool P-512
   (9) secp256k1
Your selection?

“NIST 曲线”是由 NIST (美国国家标准与技术研究院,一个美国政府机构)设计的,所以我们不知道其是否有潜在的缺陷。众所周知,自由软件社区不相信“权威”。“Brainpool 曲线”来自欧洲,这也来自“权威”。所以两者我们都不推荐。根据信息, SCEP256K1 不安全[1],但我尚未进行详细的调查。因此,ECC选项中建议仅使用“ Curve25519”。但是,Curve25519 存在一个问题,那就是,您只能使用固定长度的密钥,这就是 EDDSA 所做的。EDDSA 的全名是 Edwards 曲线数字签名算法。如果选择“ Curve25519”,则将使用 CV25519 加密,并使用 ED25519 签名,这是EDDSA的算法之一。并且“ED25519”并不比另一个选择, 4096 位的 RSA 更安全。

在这里,我们最终推荐 (1) RSA and RSA,并使用4096密钥长度,它将使用 RSA 生成一个主密钥,然后也将带有 RSA 的加密密钥,作为您的选择。如果输入命令,您将得到:

$ gpg --full-gen-key --expert
gpg (GnuPG) 2.2.31; Copyright (C) 2021 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.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
   (9) ECC and ECC
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (13) Existing key
  (14) Existing key from card
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096
Requested keysize is 4096 bits       
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want for the subkey? (3072) 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 2y
Key expires at Tue May 14 15:52:16 2024 CST
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name:

有一个新事物,到期时间。 当然,您可以选择永不过期并输入0。但是,我们不建议这样做。 想象一下,您会失去私钥,或者忘记了私钥的密码,而您无法让朋友知道这一点。 这意味着,您不能解密发送给您的消息,并且您无能为力。如果人们拥有您的“可用”钥匙之一,那么即使钥匙不再可用,他们也可能不会去寻找新的钥匙。

You can always extend your expiration date, even after it has expired! This “expiration” is actually more of a safety valve or “dead-man switch” that will automatically trigger at some point.If you have access to the secret key material, you can untrigger it.[2]

即使在过期之后,您也可以始终延长到期日期! 实际上,这种“到期”更像是安全阀或“死人开关”,它会在某个时候自动触发。如果您可以访问秘密钥匙材料,则可以阻止触发它。 因此,在这里,我们建议使用少于两年的到期日期。 您可以设置一个日历事件,以提醒您有关您的到期日期。

然后输入您的个人信息,这将您标识为 UserID。 它将是公共密钥证书的一部分,这就是证书将证明的东西,你真的是你,毕竟所有证书总得证明某些内容。

未完待续

参考

[1]:2021年,用更现代的方法使用PGP(中)

[2]:OpenPGP Best Practices



如果页面有错误,请联系 [email protected] (PGP 指纹: F557 32D7 EBF0 7DD0 7072 AF9F 5C23 6BC4 C691 3982)