Thread: BIO *PEM = BIO_new( BIO_s_mem() ); Doesn't compile?

  1. #1
    Registered User
    Join Date
    Nov 2008
    Location
    Mt Umunum, CA
    Posts
    16

    BIO *PEM = BIO_new( BIO_s_mem() ); Doesn't compile?

    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?

  2. #2

  3. #3
    Registered User
    Join Date
    Nov 2008
    Location
    Mt Umunum, CA
    Posts
    16
    Solved! My problem was on line 7
    BIO *BIO = BIO_new( BIO_s_mem() );
    redefined the term "BIO". Changed that line
    BIO *Key = BIO_new( BIO_s_mem() );
    and all other references to the structure named BIO to a structure named Key now it compiles.

    Thanks for your time.
    Last edited by MrUmunhum; 03-01-2017 at 04:11 PM. Reason: clearity

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. not sure why this doesn't compile
    By Dave Couture in forum C Programming
    Replies: 5
    Last Post: 08-18-2012, 05:08 AM
  2. exp function doesn't compile
    By VanJay011379 in forum C Programming
    Replies: 2
    Last Post: 09-16-2006, 02:02 PM
  3. Doesn't Compile
    By Justin C in forum C++ Programming
    Replies: 12
    Last Post: 04-29-2005, 06:40 PM
  4. Replies: 3
    Last Post: 03-07-2003, 09:06 PM

Tags for this Thread