Convert Array char to FILE pointer in C

0

This is working with the PEM_read_PrivateKey () function

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

of OpenSSL and I want to pass the first argument directly with Array from the Key file, for example.

char key[] = {0x33, 0x53, 0x73, 0x62, 0x4e, 0x52, 0x67, 0x54, 0x54, 0x69, 0x59, 0x57, 0x35, 0x36, 0x73, 0x5a}....
EVP_PKEY *PEM_read_PrivateKey(key, EVP_PKEY **x,pem_password_cb *cb, void *u);
    
asked by Mr Jhon 30.12.2016 в 01:05
source

1 answer

1

You'll have to use the other function family, the ..._bio_...

The structure BIO provided by OpenSSL allows you just that, use your own abstractions of I / O.

In your case,

char key[] = { ... };
BIO *mem;

mem = BIO_new_mem_buf( key, TAMAÑO ); // ¡ Cuidado con strlen( ) si no hay 0 al final !

EVP_PKEY *PEM_read_bio_PrivateKey( mem, EVP_PKEY **x, pem_password_cb *cb, void *u );
    
answered by 30.12.2016 / 06:40
source