如何使用收件人的电子邮件地址而不是指纹加密Python GNUPG(GPG)?

发布于 2025-01-31 18:37:59 字数 859 浏览 1 评论 0原文

如何使用收件人的电子邮件地址而不是指纹加密Python-gnupg(gnupg / gpg / openPGP)?

示例 show 显示(在我的Ubuntu上失败了20.04/这样的事情,但这是一个旧的示例

encrypted_data = gpg.encrypt(unencrypted_string, '[email protected]')

; “> this 和 this )不要提及收件人电子邮件地址 - 在当今的环境中,仅(大概是)公开键的指纹是可能的227991/98033“> keyserver ?

我的测试

How to Python-gnupg (GnuPG / GPG / OpenPGP) encrypt with recipient's email address rather than their fingerprint?

This example shows (which failes on my Ubuntu 20.04 / such a thing, but it's an old example; excerpt:

encrypted_data = gpg.encrypt(unencrypted_string, '[email protected]')

More-current (maybe?) references (like this and this) do not mention recipient email addresses, seemingly requiring numeric-only fingerprints for (presumably) public-key identication. Is it possible in today's environment (to identify a key solely by it's associated email_address/identity)? Possibly requiring a keyserver?

My tested python-gnupg system versions.

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

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

发布评论

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

评论(1

独留℉清风醉 2025-02-07 18:37:59

查看问题中的版本编号,您似乎正在使用 pretty-bad-protocol 重写,自2018年以来一直没有更新。

如果您只需安装python-gnupg

$ pip install python-gnupg

您获得版本0.4.9,该 ,几天前

Collecting python-gnupg
  Downloading http://.../python_gnupg-0.4.9-py2.py3-none-any.whl (18 kB)
Installing collected packages: python-gnupg
Successfully installed python-gnupg-0.4.9

使用此版本的gnupg模块,您的代码毫无问题地工作:

>>> import gnupg
>>> gpg = gnupg.G
gnupg.GPG(     gnupg.GenKey(
>>> gpg = gnupg.GPG()
>>> res = gpg.encrypt("this is a test", "[email protected]")
>>> res.data
b'-----BEGIN PGP MESSAGE-----\n...\n-----END PGP MESSAGE-----\n'
>>>

使用指纹当然是更好的,因为您的钥匙扣中可能有多个键,并且您无法确定哪个键你会得到的。使用指纹确保您获得该特定键。

Looking at the version number in your question, you appear to be using the pretty-bad-protocol rewrite, which hasn't been updated since 2018.

If you simply install python-gnupg:

$ pip install python-gnupg

You get version 0.4.9, which was released just a few days ago:

Collecting python-gnupg
  Downloading http://.../python_gnupg-0.4.9-py2.py3-none-any.whl (18 kB)
Installing collected packages: python-gnupg
Successfully installed python-gnupg-0.4.9

Using this version of the gnupg module, your code works without a problem:

>>> import gnupg
>>> gpg = gnupg.G
gnupg.GPG(     gnupg.GenKey(
>>> gpg = gnupg.GPG()
>>> res = gpg.encrypt("this is a test", "[email protected]")
>>> res.data
b'-----BEGIN PGP MESSAGE-----\n...\n-----END PGP MESSAGE-----\n'
>>>

It is of course better to use a fingerprint, because you may have multiple keys in your keychain with the same email address, and you can't be certain which one you'll get. Using a fingerprint ensures that you get that specific key.

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