有没有办法在 OpenSSL 中使用我通过 Crypto++ API 生成的 RSA 密钥?我正在寻找一种以 Crypto++ 和 OpenSSL 都可以轻松打开密钥的格式存储密钥的方法。
我正在编写一个许可方案,并且想要使用 Crypto++ API 来验证签名和解密文件,但是为了生成许可证文件,我想要使用 Web 界面(可能使用 PHP,它只支持 OpenSSL)来生成和加密/签署许可证。
我会使用 Crypto++ 编写这两个应用程序并从 PHP 调用它,但由于私钥将以加密形式存储,因此必须将密码传递给应用程序并在命令行上传递它似乎不是一个好的选择对我来说。
Is there a way to use the RSA keys I've generated with the Crypto++ API in OpenSSL? What I am looking for is a way to store the keys in a format that both Crypto++ and OpenSSL can easily open them.
I'm writing a licensing scheme and would want to verify signatures and decrypt files using the Crypto++ API, but to generate the license files I would want to use a web interface (probably using PHP, which only supports OpenSSL) to generate and encrypt/sign the licenses.
I would write both applications using Crypto++ and call it from the PHP, but since the private key will be stored in a encrypted form, a password must be passed to the application and passing it on the command line doesn't seems to be a good idea to me.
发布评论
评论(3)
Crypto++ 和 OpenSSL 都可以处理 PKCS#8 编码的密钥。在 crypto++ 中,您可以像这样生成密钥并转换为 PKCS#8 缓冲区,
现在您只需将字节传递给 PHP 即可。您可以将其保存在文件中,然后发送消息。
唯一的问题是 PHP 的 OpenSSL 接口仅接受 PEM 编码的 PKCS#8。您可以在 PHP 中轻松地将 DER 编码的缓冲区转换为 PEM,
如果您愿意,还可以在 C++ 中将 PKCS#8 转换为 PEM。从 PHP 代码中可以看出该算法非常简单。
OpenSSL 如今非常流行。我不认为有任何理由将 Crypto++ 用于像这样的常见加密应用程序。
Both Crypto++ and OpenSSL can handle PKCS#8 encoded keys. In crypto++, you can generate keys and convert to PKCS#8 buffer like this,
Now you just need to pass the bytes to PHP. You can save it in a file, send in a message.
The only gotcha is that PHP's OpenSSL interface only accepts PEM encoded PKCS#8. You can easily convert DER-encoded buffer into PEM like this in PHP,
You can also convert PKCS#8 to PEM in C++ if you prefer. The algorithm is very simple as you can see from the PHP code.
OpenSSL is so prevalent nowadays. I don't see any reason to use Crypto++ for common crypto applications like this.
是的。除了 X.509 和 PKCS #8 编码密钥(ZZ Coder 的答案)之外,您还可以使用 PEM 编码密钥(包括加密密钥)。 2014 年 7 月,为 OpenSSL 互操作向该项目提供了对 PEM 编码密钥的支持。
要使用 PEM 编码密钥,您需要获取 Crypto++ PEM Pack 并重新编译库。 PEM Pack 不是 Wei Dai 在 Crypto++ 网站 上提供的 Crypto++ 库的一部分。
安装并重新编译后,它就像这样简单:
密钥在磁盘上看起来像这样:
相关:有关其他有用的 Crypto++ 补丁,请参阅 类别:补丁 页面。
Yes. In addition to X.509 and PKCS #8 encoded keys (ZZ Coder's answer), you can also use PEM encoded keys including encrypted keys. Support for PEM encoded keys was donated to the project in July, 2014 for OpenSSL interop.
To use the PEM encoded keys, you need to fetch the Crypto++ PEM Pack and recompile the library. The PEM Pack is not part of the Crypto++ library as provided by Wei Dai at the Crypto++ website.
Once you install and recompile, its as simple as:
The keys look like so on-disk:
Related: for other useful Crypto++ patches, see the Category:Patch page on the Crypto++ wiki.
试试这个链接:
http://www.cryptopp.com/fom-serve/cache/62。 html
看来您需要使用 PKCS#8 并从 DER 转换为 PEM 格式才能在 OpenSSL 中使用密钥。我不确定您是否能够使用一个文件来完成这两个任务。
我只使用过 OpenSSL,所以我不确定 Crypto++ 有哪些选项。我通过在 Google 中搜索这些术语找到了上面的链接:Crypto++ RSA OpenSSL。
DER 是 OpenSSL 密钥和证书的二进制格式。
PEM 是 OpenSSL 的文本格式。
Try this link:
http://www.cryptopp.com/fom-serve/cache/62.html
It looks like you'll need to use PKCS#8 and convert from DER to PEM format to be able to use the keys in OpenSSL. I'm not sure if you'll be able to use a single file for both.
I've only used OpenSSL so I'm not sure what options you have with Crypto++. I found the link above by searching Google for these terms: Crypto++ RSA OpenSSL.
DER is OpenSSL's binary format for keys and certificates.
PEM is OpenSSL's text format.