您必须具有公共密钥来验证使用相应的私有密钥进行的签名,但是您不必签名,甚至不必在本地签名。在这种情况下,您会收到GPG的警告,提示密钥不可信。
这是我使用自己的密钥签名的文件进行的测试,但是在未导入密钥的系统上:
[ben@seditious tmp]$ gpg -v --verify thing.txt.gpg
gpg: original file name='thing.txt'
gpg: Signature made Thu 26 Sep 2013 06:51:39 AM EST using RSA key ID 35C7553C
gpg: Can't check signature: public key not found
[ben@seditious tmp]$ gpg -v --status-fd 1 --verify thing.txt.gpg
gpg: original file name='thing.txt'
gpg: Signature made Thu 26 Sep 2013 06:51:39 AM EST using RSA key ID 35C7553C
[GNUPG:] ERRSIG 7FF2D37135C7553C 1 10 00 1380142299 9
[GNUPG:] NO_PUBKEY 7FF2D37135C7553C
gpg: Can't check signature: public key not found
[ben@seditious tmp]$
不幸的是,Harry的建议没有用,它确实提取了更多信息,但不足以使用。
如您所见,获得的最多信息是用于进行签名的子项的密钥ID和进行签名的时间。这与pgpdump(或--list-packets)可用的数据匹配:
bash-3.2$ pgpdump thing.txt.gpg
Old: Compressed Data Packet(tag 8)
Comp alg - ZLIB <RFC1950>(comp 2)
Old: One-Pass Signature Packet(tag 4)(13 bytes)
New version(3)
Sig type - Signature of a binary document(0x00).
Hash alg - SHA512(hash 10)
Pub alg - RSA Encrypt or Sign(pub 1)
Key ID - 0x7FF2D37135C7553C
Next packet - other than one pass signature
Old: Literal Data Packet(tag 11)(24 bytes)
Format - binary
Filename - thing.txt
File modified time - Thu Sep 26 06:51:39 EST 2013
Literal - ...
Old: Signature Packet(tag 2)(412 bytes)
Ver 4 - new
Sig type - Signature of a binary document(0x00).
Pub alg - RSA Encrypt or Sign(pub 1)
Hash alg - SHA512(hash 10)
Hashed Sub: signature creation time(sub 2)(4 bytes)
Time - Thu Sep 26 06:51:39 EST 2013
Sub: issuer key ID(sub 16)(8 bytes)
Key ID - 0x7FF2D37135C7553C
Hash left 2 bytes - f0 97
RSA m^d mod n(3066 bits) - ...
-> PKCS-1
bash-3.2$
如您所见,它提供了哈希算法,密钥类型的详细信息(我的签名密钥是3072位RSA子密钥和该子密钥的密钥ID,但是没有什么可识别主密钥。该信息仅是在您拥有公钥并验证签名时显示。
然后,我在该系统上导入了我的公钥,然后再次尝试:
[ben@seditious tmp]$ gpg -v --verify thing.txt.gpg
gpg: original file name='thing.txt'
gpg: Signature made Thu 26 Sep 2013 06:51:39 AM EST using RSA key ID 35C7553C
gpg: using subkey 35C7553C instead of primary key 73590E5D
gpg: using PGP trust model
gpg: Good signature from "Ben M <ben@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M (backup email address) <benm@REDACTED>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: DB47 24E6 FA42 86C9 2B4E 55C4 321E 4E23 7359 0E5D
Subkey fingerprint: B7F0 FE75 9387 430D D0C5 8BDB 7FF2 D371 35C7 553C
gpg: binary signature, digest algorithm SHA512
[ben@seditious tmp]$
现在,它可以识别密钥并将其与主密钥匹配。但是,可以减少这些警告的性质,如下所示:
[ben@seditious tmp]$ gpg -v --verify --trust-model always thing.txt.gpg
gpg: original file name='thing.txt'
gpg: Signature made Thu 26 Sep 2013 06:51:39 AM EST using RSA key ID 35C7553C
gpg: using subkey 35C7553C instead of primary key 73590E5D
gpg: Good signature from "Ben M <ben@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M (backup email address) <benm@REDACTED>"
gpg: WARNING: Using untrusted key!
gpg: binary signature, digest algorithm SHA512
[ben@seditious tmp]$
仍然有一个警告,它是一个不受信任的密钥,但并不是很大,因此删除冗长只会将其减少为:
[ben@seditious tmp]$ gpg --verify --trust-model always thing.txt.gpg
gpg: Signature made Thu 26 Sep 2013 06:51:39 AM EST using RSA key ID 35C7553C
gpg: Good signature from "Ben M <ben@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M (backup email address) <benm@REDACTED>"
gpg: WARNING: Using untrusted key!
[ben@seditious tmp]$
验证阶段需要公用密钥,因为公用密钥用于将签名者生成的数据与其私钥进行匹配。简单来说,可以将其视为加密的补充,其中需要私钥将加密后的数据解密为公钥。
注意:在本示例中,我对UID进行了一些调整,但是每个获得该密钥的人都会看到它们的真实含义。否则,输出为直接复制并粘贴。
编辑:如果您使用非ASCII铠装格式(例如,.gpg文件而不是.asc文件),则可以像密钥环一样直接调用公钥文件。即使这样,您仍然需要公共密钥。为此,命令如下所示:
[ben@seditious ~]$ gpg -v --no-default-keyring --keyring /tmp/mykey.gpg --verify /tmp/thing.txt.gpg
gpg: original file name='thing.txt'
gpg: Signature made Thu 26 Sep 2013 06:51:39 AM EST using RSA key ID 35C7553C
gpg: using subkey 35C7553C instead of primary key 73590E5D
gpg: using PGP trust model
gpg: Good signature from "Ben M <ben@REDACTED>"
gpg: aka "Ben M (backup email address) <benm@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: aka "Ben M <ben.m@REDACTED>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: DB47 24E6 FA42 86C9 2B4E 55C4 321E 4E23 7359 0E5D
Subkey fingerprint: B7F0 FE75 9387 430D D0C5 8BDB 7FF2 D371 35C7 553C
gpg: binary signature, digest algorithm SHA512
[ben@seditious ~]$
gpg --status-fd 1 --verify (thefile)
在其输出中以第一个字符串形式给出进行签名的密钥的指纹。