Hi group,

I am still getting uses to SSL and I need a little help with RSA. I have a small
test program that I wrote to help me. My latest problem is how do I extract
the public key from the RSA structure to send to a SSL client? Here is my test program:
#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <signal.h>
#include <termios.h>
#include <termio.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wordexp.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <openssl/rsa.h> #include <openssl/rand.h>
#include <openssl/blowfish.h>

#define SAY printf( "In: '%s', Out: '%s'\n", In, Out );

#define   ON_ERR(Test,M, Action)                    \
  if( Test ) {                                                          \
    sprintf(Work,"%s %s\n", M, strerror(errno) );            \
    printf( "%s",Work);                                                 \
    Action; }

RSA  *My_RSA;
RSA  *My_Key;
char *Public_Key[1024];
char  In[  100];
char  Out[ 100];
char  Work[100];
int   RC, Size, Len, Run;

int
main( ) {

  My_RSA = RSA_generate_key( 1024, 65537, NULL, NULL );
ON_ERR( !My_RSA, "generating RSA key failed\n", return 0; ) for( Run = 1; Run; ) {
    printf( "Enter string: " );fflush(stdout);
    fgets( In, 80, stdin );
    if( In[0] == '\n' ) break;
    Len = strlen(In)-1;
    In[Len-1] = Out[0] = '\0';
    SAY;
    Size = Encrypt( );
    SAY;
    Decrypt( Size );
    SAY; }
return 1; }

/* ------------------------------------------------------------------ */

int
Encrypt( ) {

Size = RSA_public_encrypt( strlen(In), In, Work, My_RSA, RSA_PKCS1_PADDING );
  ON_ERR( Size < 0, "Encrypt failed: ", return 0; );
  printf( "New size: %d\n", Size );
return Size; }

/* ------------------------------------------------------------------ */

int
Decrypt( int Size ) {

  RC = RSA_private_decrypt( Size, Work, Out, My_RSA, RSA_PKCS1_PADDING );
  ON_ERR( RC < 0, "Decrypt failed: ", return 0; );

  return 0; }

/* ------------------------------------------------------------------ */





--
William Estrada
[EMAIL PROTECTED]
Mt-Umunhum-Wireless.net ( http://Mt-Umunhum-Wireless.net )
Ymessenger: MrUmunhum


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to