如何导入 OpenPGP 卡/YubiKey 备份加密密钥

如何导入 OpenPGP 卡/YubiKey 备份加密密钥

当我在 YubiKey 上生成新的 OpenPGP 密钥时,它会让我选择将加密密钥的副本保存为备份,如下所示:

$ gpg --edit-card

Reader ...........: Yubico Yubikey NEO U2F CCID 00 00
Application ID ...: D2760001240102000006054943550000
Application type .: OpenPGP
Version ..........: 2.0
Manufacturer .....: Yubico
Serial number ....: 05494355
Name of cardholder: [not set]
Language prefs ...: [not set]
Salutation .......: 
URL of public key : [not set]
Login data .......: [not set]
Signature PIN ....: forced
Key attributes ...: rsa2048 rsa2048 rsa2048
Max. PIN lengths .: 127 127 127
PIN retry counter : 3 3 3
Signature counter : 0
Signature key ....: [none]
Encryption key....: [none]
Authentication key: [none]
General key info..: [none]

gpg/card> admin
Admin commands are allowed

gpg/card> generate
Make off-card backup of encryption key? (Y/n) Y

这将导致在我的 YubiKey 上生成密钥并将文件存储在我的 GNUPGHOME 文件夹中,就像sk_5F91DF31AB07820C.gpg加密密钥一样。

我的问题是,如果我丢失了 YubiKey,我该如何将该密钥重新导入到可用形式?

  • 我原本期望能在本地机器上创建一个新密钥,然后将该备份密钥作为新子密钥导入,但我找不到这样做的方法。

  • 我看到下面有一个gpg --edit-key名为的选项bkuptocard,它似乎可以做我想要做的事情,但是当我尝试这样做时,它似乎只将密钥加载到 YubiKey 上的插槽中,但实际上并没有使其可用于 gpg 中的解密。

如果我丢失了 YubiKey,我该如何使用这个备用密钥?

答案1

备份 sk_xxx.gpg

首先导入公钥:

gpg --import public.pgp

添加数据以避免因“无用户 ID”而失败:

printf '\xb4\x06foobar' >> sk_xxx.gpg

导入更新的备份密钥:

gpg --allow-non-selfsigned-uid --import sk_xxx.gpg

答案2

gpg --import它。

该文件的内容将存储在您的本地 GnuPG 密钥环中,此时您可以直接使用子密钥或将​​其移动到新的智能卡(如果您愿意)。

相关内容