从 RSA 密钥对中获取参数

Getting params out of an RSA keypair

我想生成一个 RSA 密钥对并记录公钥参数(模数和指数、n 和 e),从现有的密钥集中(der 格式)获取参数,或者从我的公钥对中生成一个公钥对自己的参数。

我是trying to do the first with Crypto++,但是它吐出的ders被openssl报告为无效。今晚 Crypto++ wiki 和文档页面也没有帮助!

然后我尝试研究使用 Crypto++ 制作的一些随机密钥参数在 openssl 中生成密钥对的方法,但几个小时后我仍然试图破译所有命令行参数。

这并不是一个安全密钥,只是一个用于我拥有的项目中某些单元测试的工作密钥,它从 JWK 获取公钥作为 (n,e) 对,并且需要验证它是否可以实际验证签名适当地。但要做到这一点,我需要私有 der 和 public (n,e),并且必须有一种比尝试使用 openssl 包装器库中的一个更简单的方法来记录密钥参数,因为它生成密钥对。

I was trying to do the first with Crypto++, but the ders it spits out are reported as invalid by openssl...

(from linked GitHub):

RSA::PublicKey publicKey(params);
FileSink pubsink("pubkey.der");
publicKey.DEREncode(pubsink);

如果要保存 subjectPublicKeyInfo,请使用 publicKey.SavesubjectPublicKeyInfo 是您考虑的 RSA 密钥加上外部 X.509 包装,如 OID 和版本号。


I then tried researching ways to generate keypairs in openssl by using some of the random key parameters Crypto++ made, but several hours later I'm still stuck trying to decipher all the command line args.

您可能会发现来自 Crypto++ wiki 的 Keys and Formats 很有帮助。它还提供 OpenSSL 和 GnuTLS 命令。


I want to either generate an RSA keypair and log the pubkey parameters (modulus and exponent, n and e), get the parameters out of an existing set of keys (in der format) or generate a pubkey pair from my own parameters.

回到这里... RSA Cryptography RSA Encryption Schemes and RSA Signature Schemes.

的 wiki 上有很多示例

一般来说,Crypto++ 对 ASN.1/DER 中的所有密钥进行编码。 LoadSave 提供 "subject info" 部分,而 DEREncodeBERDecode 只提供 "raw key" 部分。再一次,看看 Keys and Formats.

如果你想处理 PEM 编码的密钥,那么你需要 PEM Pack。它是一个附加组件,您必须下载它,然后使用包含的 PEM 包构建库。

如果您提供具体数据,例如您尝试处理的十六进制编码密钥,那么我们可以详细说明您应该做什么。