1

I need to hard code my RSA private/public key in my app, the key is actually a file in PEM format, how can I load it from memory by calling OpenSSL routines?

janw
  • 8,758
  • 11
  • 40
  • 62
Gerry
  • 86
  • 2
  • 13

2 Answers2

1

You need to use OpenSSL's BIO functions to allow reading from a memory location:

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);

Run man 3 bio, man 3 BIO_new_mem_buf, and man 3 pem for more details.

dbush
  • 205,898
  • 23
  • 218
  • 273
0

Try EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);

  • 1
    Needs a massive amount of expansion for this answer, if it is an answer, to be usable. Sadly, you can't even point OP at the man page because the man page is a cryptic mess. – user4581301 Sep 07 '15 at 20:26