【问题标题】:How to decrypt a PGP file using Public Key in PGPy如何在 PGPy 中使用公钥解密 PGP 文件
【发布时间】:2020-01-08 11:02:22
【问题描述】:

我有一个公开共享给我,我正在加载它,如下所示:

key_path = os.environ.get('ESB_FILES_PUBLIC_KEY')
key, _ = pgpy.PGPKey.from_file(key_path)

我尝试使用此密钥解密文件

message_from_file = pgpy.PGPMessage.from_file(filepath)
raw_message = key.decrypt(message_from_file).message
print(raw_message)

它不起作用,我收到了这个错误 pgpy.errors.PGPError: Expected: is_public == False. Got: True

关于如何仅使用公钥在 Python 中解密 PGP 文件的任何想法。 供参考:我目前正在使用这个库https://pgpy.readthedocs.io/en/latest/examples.html

谢谢

【问题讨论】:

  • 不能用公钥解密,必须有私钥。这就是非对称密码学的非对称部分。
  • 不过,这是个好问题。令人惊讶的是,pgpy 文档没有提供如何使用私钥解密公钥加密消息的普通用例示例。为他们感到羞耻。

标签: python encryption gpgpu pgp


【解决方案1】:

PGP 使用非对称加密。有一个公钥是公开的,只能加密,而私钥只能解密。我发现有用的一个很好的解释是“PGP 是如何工作的”下的https://www.freecodecamp.org/news/how-does-pretty-good-privacy-work-3f5f75ecea97/

在您所指的文档中:https://pgpy.readthedocs.io/en/latest/examples.html#encrypting-decrypting-messages-with-a-public-key 它说“使用密钥加密需要公钥,而解密需要私钥。”

如果您生成了密钥,您的密钥环上应该有私钥,您可以将其导出为 .asc 并解密。

【讨论】:

  • 文档没有关于如何生成公钥和私钥的任何信息
猜你喜欢
  • 2020-12-13
  • 1970-01-01
  • 2011-05-10
  • 1970-01-01
  • 2022-10-31
  • 2012-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多