2

Currently I have my private key saved in a file, private.key, and I use the following function to load it:

RSA *r = PEM_read_RSAPrivateKey("private.key", NULL, NULL, NULL);

This works perfectly but I'm not happy with the file-based format; I want to save my key in pure binary form (ie, no base64 or similar) in a char* variable and load/save the key from/to it. This way I have much more freedom: I'll be able to store the key directly into the application const char key[] { 0x01, 0x02, ... };, send it over a network socket, etc.

Unfortunately though I haven't found a way to do that. The only way to save and load a key I know of reads/saves it to a file directly.

1 Answer 1

7

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

const unsigned char *p = key;
RSA *r = d2i_RSAPrivateKey(NULL, &p, keylen);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.