Tutorial by Examples

In order to generate an RSA key, an EVP_PKEY must first be allocated with EVP_PKEY_new: EVP_PKEY *pkey; pkey = EVP_PKEY_new(); An exponent for the key is also needed, which will require allocating a BIGNUM with BN_new and then assigning with BN_set_word: BIGNUM *bn; bn = BN_new(); BN_set_wor...
An EVP_PKEY can be saved directly to disk in a several formats. PEM_write_PrivateKey is used to save EVP_PKEY in a PEM format: FILE *f; f = fopen("key.pem", "wb"); PEM_write_PrivateKey( f, /* use the FILE* that was opened */ pkey, /* EV...
To load a private key directly from disk, use the PEM_read_PrivateKey function: FILE *f; EVP_PKEY *pkey; f = fopen("key.pem", "rb"); PEM_read_PrivateKey( f, /* use the FILE* that was opened */ &pkey, /* pointer to EVP_PKEY structure */ NULL, /* passwor...

Page 1 of 1