Hi group,
This is a follow on to my other post:RSA key generate then encrypt/decrypt error
I am now tryin to create a public RSA to use to encrypt a message for a peer.
I found this helpful link:c - How to translate pem public key into openssl RSA* structure - Stack Overflow and wrote this function:
Code:
void
Make_RSA( RSA* RSA_Pair, RSA* RSA, char* Type ) { // Makw_RSA
int RC;
// Extract Key from RSA Key pair
BIO *BIO = BIO_new( BIO_s_mem() );
if( strcmp( Type, "public" ) ) {
PEM_write_bio_RSAPrivateKey( BIO, RSA_Pair,
NULL, NULL, 0, NULL, NULL); }
else {
PEM_write_bio_RSAPublicKey( BIO, RSA_Pair ); }
size_t BIO_Len = BIO_pending( BIO );
char *BIO_Key = malloc( BIO_Len + 1 );
RC = BIO_read( BIO, BIO_Key, BIO_Len );
BIO_Key[ BIO_Len ] = '\0';
// Let's see the data
printf( BLUE "BIO Key type %s\n" OFF, Type );
Dump( (char*) BIO_Key, BIO_Len );
// Now fill in to RSA
BIO *PEM = BIO_new( BIO_s_mem() );
PEM = BIO_new_mem_buf( BIO_Key, BIO_Len );
EVP_PKEY* EVP_PEM_Key = d2i_PUBKEY_bio( PEM, NULL);
RSA = EVP_PKEY_get1_RSA( EVP_PEM_Key );
// Free used memory
EVP_PKEY_free( EVP_PEM_Key ) ;
BIO_free( BIO );
BIO_free( PEM );
return; }
But it will not compile?gcc -I. -I/usr/include/openssl/ -g rsa.c -o myrsa -lcrypto && gdb myrsa
rsa.c: In function ‘Make_RSA’:
rsa.c:141:8: error: ‘PEM’ undeclared (first use in this function)
BIO *PEM = BIO_new( BIO_s_mem() );
^
rsa.c:141:8: note: each undeclared identifier is reported only once for each function it appears in
I have no idea what it is complaining about?
Can you see my problem?