创建可以使用 Python TLSLite parseAsPublicKey 加载的公钥

发布于 2025-01-02 13:54:33 字数 890 浏览 2 评论 0原文

我想从 Python 的 TLSlite 库加载公钥。

密钥可以以我们喜欢的任何方式创建,只要格式是通用的 - 到目前为止,我使用的是使用 openssl 命令行工具创建的 PEM 密钥:

   openssl genrsa 2048 > private.pem

然后:

   openssl rsa -in private.pem -pubout > public.pem

这是结果:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCw0zAfn11dltN7b3HL+vDsp+oS
rhwAYPjtpMtsdKp7/i5fCf2oAo2wSBPfjM7q9DAZgPrnlzDYldIZ5MooUL2EJ59c
6TRQN/2pBeE59nzvRif1DSgWgZhK7mvjo4YtLS10eqOxY5A8VVyKmNzQ15ILbYwg
8ZwXoiMJJPECmt0iswIDAQAB
-----END PUBLIC KEY-----

密钥将被加载:

   from libs.tlslite.utils import keyfactory
   pubkey = open('public.pem').read()
   keyfactory.parsePEMKey(pubkey, private=False)

但是这个因语法错误而失败。剥离换行符、仅使用破折号之间的字符串部分等都会失败。

我很高兴使用不同的通用密钥格式,但是我需要 TLSLite 或其他纯 Python 解决方案才能读取该文件,因为我使用的是 Google AppEngine。

I'd like to load a public key from Python's TLSlite Library.

The key can be created any way we like, as long as the format is common - so far I'm using a PEM key created with the openssl commandline tool:

   openssl genrsa 2048 > private.pem

And then:

   openssl rsa -in private.pem -pubout > public.pem

Here's the results:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCw0zAfn11dltN7b3HL+vDsp+oS
rhwAYPjtpMtsdKp7/i5fCf2oAo2wSBPfjM7q9DAZgPrnlzDYldIZ5MooUL2EJ59c
6TRQN/2pBeE59nzvRif1DSgWgZhK7mvjo4YtLS10eqOxY5A8VVyKmNzQ15ILbYwg
8ZwXoiMJJPECmt0iswIDAQAB
-----END PUBLIC KEY-----

The key will be loaded with:

   from libs.tlslite.utils import keyfactory
   pubkey = open('public.pem').read()
   keyfactory.parsePEMKey(pubkey, private=False)

However this fails with a SyntaxError. Stripping newlines, only using the part of the string between the dashes, etc. all fail.

I am quite happy to use a different, common key format, however I require TLSLite or another pure-Python solution to be able to read the file, as I am using Google AppEngine.

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

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

发布评论

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

评论(1

躲猫猫 2025-01-09 13:54:33

您可能应该包含 implementations 参数,如下所示:

parsePEMKey(key_data, private=False,implementations=['python'])

You should probably include the implementations argument, as in:

parsePEMKey(key_data, private=False, implementations=['python'])

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