whatisinaname
whatisinaname

Reputation: 343

Reading RSA keys from strings

I am trying to use RSA to decrypt some stuff using OpenSSL. I want to load a public key. The default function provided to do this is PEM_read_RSA_PUBKEY() which requires a file descriptor.

I would like to embed the keys into the program as strings. Is there any way to achieve this?

Upvotes: 1

Views: 839

Answers (1)

caf
caf

Reputation: 239011

Use d2i_RSA_PUBKEY to load directly from a buffer containing binary DER format:

const unsigned char *p = key;
RSA *r = d2i_RSA_PUBKEY(NULL, &p, keylen);

Upvotes: 1

Related Questions