I have the following code:
#include <openssl/bn.h>
#include <openssl/rsa.h>
unsigned char* key;
RSA* rsa = RSA_new();
rsa = RSA_generate_key(1024,65537,NULL,NULL);
//init pubkey
key[BN_num_bytes(rsa->n)] = '\0';
BN_bn2bin(rsa->n, key);
printf("RSA Pub: %s\n", key);
RSA_free( rsa );
rsa = NULL;
The debugger is telling me that I have an issue "Access violation writing location" on the line
key[BN_num_bytes(rsa->n)] = '\0';
If I comment out that line the issue just moves down to
BN_bn2bin(rsa->n, key);
any suggestions on how to fix this issue would be great.