GNUPG指纹未识别为加密的有效收件人

发布于 2025-01-30 12:09:08 字数 620 浏览 1 评论 0原文

密钥的GNUPG指纹未被确定为加密的有效收件人。根据此doc https://pythonhosted.org/python-python-gython-gnupg/ #encryptig 我们可以使用指纹。但是它不起作用。

>>> import gnupg
>>> gpg = gnupg.GPG(gnupghome="/home/user/.gnupg")
>>> key_data = open('/home/user/path/to/public_key.pgp').read()
>>> import_result = gpg.import_keys(key_data)
>>> test_status = gpg.encrypt('test', import_result.fingerprints[0])
>>> test_status.status
'invalid recipient'
>>> 

gnupg fingerprint of key is not identified as valid recipient for encryption. According to this doc https://pythonhosted.org/python-gnupg/#encryption we can use fingerprint. But its not working.

>>> import gnupg
>>> gpg = gnupg.GPG(gnupghome="/home/user/.gnupg")
>>> key_data = open('/home/user/path/to/public_key.pgp').read()
>>> import_result = gpg.import_keys(key_data)
>>> test_status = gpg.encrypt('test', import_result.fingerprints[0])
>>> test_status.status
'invalid recipient'
>>> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守护在此方 2025-02-06 12:09:08

如果要从命令行尝试相同的过程,则在尝试将消息加密到收件人(gpg -ea -ea -r&lt< enterprint>)时,会看到以下错误

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

Use this key anyway? (y/N)

。在将其用作收件人之前“信任”密钥。您可以使用trust_keys方法来执行此操作:

>>> import_result = gpg.import_keys(key_data)
>>> gpg.trust_keys(import_result.fingerprints[0], 'TRUST_ULTIMATE')
<gnupg.TrustResult object at 0x7f2ab0b22e30>
>>> test_status = gpg.encrypt('test', import_result.fingerprints[0])
>>> test_status.status
'encryption ok'

另外,您可以设置ewnder_trust参数:

>>> import_result = gpg.import_keys(key_data)
>>> test_status = gpg.encrypt('test', import_result.fingerprints[0], always_trust=True)
>>> test_status.status
'encryption ok'

ewndery_trust option 在文档中

If you were to attempt the same process from the command line, you would see the following error when attempting to encrypt a message to the recipient (gpg -ea -r <fingerprint>):

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

Use this key anyway? (y/N)

It is necessary to "trust" the key before you can use it as a recipient. You can do this using the trust_keys method:

>>> import_result = gpg.import_keys(key_data)
>>> gpg.trust_keys(import_result.fingerprints[0], 'TRUST_ULTIMATE')
<gnupg.TrustResult object at 0x7f2ab0b22e30>
>>> test_status = gpg.encrypt('test', import_result.fingerprints[0])
>>> test_status.status
'encryption ok'

Alternately, you can set the always_trust parameter:

>>> import_result = gpg.import_keys(key_data)
>>> test_status = gpg.encrypt('test', import_result.fingerprints[0], always_trust=True)
>>> test_status.status
'encryption ok'

The always_trust option is described in the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文