从文件加载 RSA 密钥
我使用 openSSL 命令创建了 2 个文件:1 个用于 RSA 公钥,2 个用于 RSA 公钥。 1 表示 RSA 私钥。如何使用 C 恢复 RSA 密钥?
具体来说,我有这些函数:
RSA_public_encrypt(read_num, in_buf, out_buf, public_key, RSA_PKCS1_PADDING);
RSA_private_decrypt(read_num, in_buf, out_buf, private_key, RSA_PKCS1_PADDING);
第四个参数,public_key 和 private_key,需要是 RSA 类型。但我只有 openSSL 命令生成的 2 个文本文件:
File 1:
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDP78B9GZ9ZFG6OnZ1PU+9BPoyLRuYJr3rSX470XjbJhmlq9DTn
NvG1pxWxrd5tjlmMWD4AkHqD7E87AafvQEiABdUXwf30LatT1w6tlyQWkM/HCN5k
....
npF+nDtKmGteLJVp5x7HHMnZaRbvcV2oUtgdmIMbqVYgbPkwO2tUfUPA6zg1fzhy
nNzQ35e/Hi0fgSHZib0CQEe4e4txXzkezomkWqwuGL8Qqp8iCbBn44mzxXTBvAQl
muFu93C/ULMzRoq4cpPgl3sS0F9s7+zR18SERerFvfc=
-----END RSA PRIVATE KEY-----
File 2:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDP78B9GZ9ZFG6OnZ1PU+9BPoyL
RuYJr3rSX470XjbJhmlq9DTnNvG1pxWxrd5tjlmMWD4AkHqD7E87AafvQEiABdUX
wf30LatT1w6tlyQWkM/HCN5kmK5WzPUYbI1q5xGy7Eox9sJ6cNwMUOT+MSDhErgB
gkgF6uG1yGrxuEVk/QIDAQAB
-----END PUBLIC KEY-----
现在,我将这 2 个文件读取到 char[] 数组中。接下来我要做的是将这 2 个数组转换为 2 个 RSA 密钥(客户端的公钥和服务器的 private_key),以便我可以使用 RSA_public_encrypt 和 RSA_private_decrypt 函数。
谢谢。
I used openSSL command to create 2 files: 1 for RSA public key & 1 for RSA private key. How do I recover RSA keys using C?
Specifically, I have these functions:
RSA_public_encrypt(read_num, in_buf, out_buf, public_key, RSA_PKCS1_PADDING);
RSA_private_decrypt(read_num, in_buf, out_buf, private_key, RSA_PKCS1_PADDING);
The 4th arguments, public_key and private_key, need to be in RSA type. But what I have are only 2 text files generated by openSSL command:
File 1:
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDP78B9GZ9ZFG6OnZ1PU+9BPoyLRuYJr3rSX470XjbJhmlq9DTn
NvG1pxWxrd5tjlmMWD4AkHqD7E87AafvQEiABdUXwf30LatT1w6tlyQWkM/HCN5k
....
npF+nDtKmGteLJVp5x7HHMnZaRbvcV2oUtgdmIMbqVYgbPkwO2tUfUPA6zg1fzhy
nNzQ35e/Hi0fgSHZib0CQEe4e4txXzkezomkWqwuGL8Qqp8iCbBn44mzxXTBvAQl
muFu93C/ULMzRoq4cpPgl3sS0F9s7+zR18SERerFvfc=
-----END RSA PRIVATE KEY-----
File 2:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDP78B9GZ9ZFG6OnZ1PU+9BPoyL
RuYJr3rSX470XjbJhmlq9DTnNvG1pxWxrd5tjlmMWD4AkHqD7E87AafvQEiABdUX
wf30LatT1w6tlyQWkM/HCN5kmK5WzPUYbI1q5xGy7Eox9sJ6cNwMUOT+MSDhErgB
gkgF6uG1yGrxuEVk/QIDAQAB
-----END PUBLIC KEY-----
Now, I read these 2 files to a char[] array. What I have to do next is convert these 2 arrays to 2 RSA keys (public key at client & private_key at server) so that I can use RSA_public_encrypt and RSA_private_decrypt functions.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 OpenSSL 加密库中的 I/O 函数,特别是PEM 函数
Take a look at the I/O functions in the OpenSSL crypto library, specifically the PEM functions