Reading Public/Private Key from Memory with OpenSSL

后端 未结 3 662
予麋鹿
予麋鹿 2020-12-06 07:02

I am using Public/Private Keys in my project to encrypt/decrypt some data.

I am hosting a public key (\"public.pem\") on a server.

\"public.pem\" looks like

3条回答
  •  鱼传尺愫
    2020-12-06 07:54

    You are on the right track. You must wrap the PEM key already in memory by means of a BIO buffer via BIO_new_mem_buf(). In other words, something like:

    BIO *bufio;
    RSA *rsa
    
    bufio = BIO_new_mem_buf((void*)pem_key_buffer, pem_key_buffer_len);
    PEM_read_bio_RSAPublicKey(bufio, &rsa, 0, NULL);
    

    The same approach is valid for an RSA private key (via PEM_read_bio_RSAPrivateKey), but in that case you most certainly need to cater for the pass phrase. Check the man page for details.

提交回复
热议问题