创建可以使用 Python TLSLite parseAsPublicKey 加载的公钥
我想从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能应该包含
implementations
参数,如下所示:parsePEMKey(key_data, private=False,implementations=['python'])
You should probably include the
implementations
argument, as in:parsePEMKey(key_data, private=False, implementations=['python'])