我为什么不能阅读PEM_read_RSAPublicKey OpenSSL的生成RSA密钥酒吧? [英] Why I can't read openssl generated RSA pub key with PEM_read_RSAPublicKey?

查看:2898
本文介绍了我为什么不能阅读PEM_read_RSAPublicKey OpenSSL的生成RSA密钥酒吧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取OpenSSL的产生这样的RSA公钥:

I'm trying to read a RSA public key generated with openssl like this:

Private Key:
    openssl genrsa -out mykey.pem 1024

Public Key afterwards:
    openssl rsa -in mykey.pem -pubout > somewhere.pub

然后我尝试阅读:

Then I try to read:

FILE *keyfile = fopen("somewhere.pub", "r");
RSA *rsa_pub = PEM_read_RSAPublicKey(keyfile, NULL, NULL, NULL);
//rsa_pub == NULL!

当我读它的工作原理私钥

When I'm reading the private key it works

FILE *keyfile = fopen("mykey.pem", "r");
RSA *rsa_pri = PEM_read_RSAPrivateKey(keyfile, NULL, NULL, NULL);
//all good

任何想法?

我读过的OpenSSL生成RSA公钥的X509关键。但我无法管理加载甚至X509酒馆关键。

I've read that openssl generate a X509 key of the RSA public key. But I could not manage to load even a X509 pub key.

感谢

推荐答案

您可以尝试 PEM_read_RSA_PUBKEY()而不是 PEM_read_RSAPublicKey的()

这是所有关于格式。

由OpenSSL的生成默认的公钥文件格式是PEM格式。

The default public key file format generated by openssl is the PEM format.

PEM_read_RSA_PUBKEY()读取PEM格式。 PEM_read_RSAPublicKey()读取PKCS#1格式。

PEM_read_RSA_PUBKEY() reads the PEM format. PEM_read_RSAPublicKey() reads the PKCS#1 format.

所以,如果你想坚持到 PEM_read_RSAPublicKey(),你可以通过指定 -outform使用PKCS#1格式生成公钥文件生成公钥时DER 选项。

So if you want to stick to PEM_read_RSAPublicKey() you could generate the public key file using the PKCS#1 format by specifying the -outform DER option when generating the public key.

这篇关于我为什么不能阅读PEM_read_RSAPublicKey OpenSSL的生成RSA密钥酒吧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆