[英]RSA key format is not supported for python
from Crypto.PublicKey import RSA
pub_key = """
-----BEGIN PGP PUBLIC KEY BLOCK-----
mykeyhere
-----END PGP PUBLIC KEY BLOCK-----
"""
public_key_object = RSA.importKey(pub_key)
This throws the following error - RSA key format is not supported
这会引发以下错误 -
RSA key format is not supported
This is a public PGP key generated with RSA-4096 encryption.这是使用 RSA-4096 加密生成的公共 PGP 密钥。 I am curious why this library could be throwing errors.
我很好奇为什么这个库会抛出错误。 Could there be invalid characters in the key?
密钥中可能有无效字符吗? Doesn't look like there are any, no forward slashes or whatnot.
看起来没有,没有正斜杠或诸如此类的东西。
For PGP you need a PGP specific library.对于 PGP,您需要一个 PGP 特定的库。 PGP, at least for the public keys, uses it's own defined format.
PGP,至少对于公钥,使用它自己定义的格式。 If you look at your cryptographic library then you will find this nugget:
如果你查看你的加密库,你会发现这个金块:
The following formats are supported for an RSA public key: RSA 公钥支持以下格式:
So the PGP key format is not supported, only X.509 keys (the certificate contains the subject public key which contains a PKCS#1 public key if RSA is used, like a Matrushka doll) and OpenSSH keys.因此不支持 PGP 密钥格式,只有 X.509 密钥(证书包含主题公钥,如果使用 RSA,则包含 PKCS#1 公钥,如 Matrushka 娃娃)和 OpenSSH 密钥。
Here is the first library that I found: py-pgp, which includes:这是我找到的第一个库:py-pgp,其中包括:
from pgp import read_key
key = read_key(data)
for "transferable" keys, which I presume are public keys.对于“可转让”密钥,我认为它们是公钥。
try python-gnupg .尝试python-gnupg 。 it takes care of everything for you
它会为你处理一切
pycryptodome is a low level library. pycryptodome是一个低级库。 we are free to pick and choose the type of key and cipher over there but we use it only if we know what we are doing ^_^
我们可以自由选择那里的密钥和密码类型,但只有当我们知道我们在做什么时才使用它^_^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.