PEM_read_RSAPublicKey and PEM_read_RSAPublicKey

PEM_read_RSAPrivateKey
PEM_read_RSAPublicKey
PEM_read_RSA_PUBKEY

写了一段程序来测试RSA加解密,结果发现无论如何公钥怎么也读不出来,后来发现读取私钥使用PEM_read_RSAPrivateKey, 但读取公钥却不能用PEM_read_RSAPublicKey, 那用什么呢?要用PEM_read_RSA_PUBKEY

why?

打开两个文件看一看,发现文件格式不一样啊(public key文件开头没有RSA标志):

private key:
—–BEGIN RSA PRIVATE KEY—–

—–END RSA PRIVATE KEY—–

publick key:
—–BEGIN PUBLIC KEY—–

—–END PUBLIC KEY—–

PEM_read_RSAPublicKey 用于读取下面格式的公钥文件:
—–BEGIN RSA PUBLIC KEY—–

—–END RSA PUBLIC KEY—–

而 PEM_read_RSA_PUBKEY 用于读取这样的:
—–BEGIN PUBLIC KEY—–

—–END PUBLIC KEY—–

至于为什么这样,openssl的一贯风格是不注释,无文档,让你自己读代码琢磨去吧。

Leave a Reply

Your email address will not be published. Required fields are marked *