This question already has answers here:
Closed 2 years ago.
Reading Public/Private Key from Memory with OpenSSL
(3个答案)
我需要在我的应用程序中硬编码我的RSA私钥/公钥,密钥实际上是
一个pem格式的文件,如何通过调用OpenSSL例程从内存中加载它?
提前谢谢

最佳答案

您需要使用OpenSSL的BIO函数来允许从内存位置读取:

BIO *key_bio;
RSA *key;
char private_key_data[] = // your private key

key_bio = BIO_new_mem_buf(private_key_data, -1);
key = PEM_read_bio_RSAPrivateKey(key_bio, NULL, NULL, NULL);

有关详细信息,请运行man 3 bioman 3 BIO_new_mem_bufman 3 pem

10-07 17:58