Hi,

I have a message digest i want to sign with my RSA private key and i just want the 
signature printed out on screen. I found a lot of
help in demos/sign.c but I still have problems.

The code i managed to write is added below. It seems to work ok... no errors... the 
signature gets printed out... but what makes me
wonder is the output format of the signature. That's not in the format I want to 
get... Shouldn't it be just ASCII? Like
sdf8gdfgfdl9fdgdl+dsf8fsjgsjgjsg009dfsf9 or something... What did I miss? Or is 
something totally wrong with the whole code? Sorry
if i'm acting like a real newbie but... that's exactly who I am :)

I'd highly appreciate if someone experienced took a look at the code and pointed out 
what I'm doing wrong.

Elen

--------------------the code that's supposed to do the signing------------------------
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/objects.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>

int main ()
{
  unsigned int siglen;
  unsigned char *sigret, data[1024];
/* plain-key.pem contains my private key*/
  static char keyfile[]  = "plain-key.pem";
/* hashfile.txt contains a message digest generated using sha1*/
  static char datafile[] = "hashfile.txt";
  RSA *pkey;
  FILE *fp, *hfp;
  int retval;

  /* Just load the crypto library error strings,
   * SSL_load_error_strings() loads the crypto AND the SSL ones */
  /* SSL_load_error_strings();*/
  ERR_load_crypto_strings();

  /* Read private key */

  fp = fopen (keyfile, "r");
  if (fp == NULL) exit (1);
  pkey = PEM_read_RSAPrivateKey (fp, NULL, NULL, NULL);
  if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1);  }
  fclose (fp);

  /* Read hashed text */
  hfp = fopen (datafile, "r");
  if (hfp == NULL) exit (1);
  fscanf (hfp, "%s", data);
  fclose (hfp);

  /* Sign the digest */
  sigret = malloc(RSA_size(pkey));
  retval = RSA_sign(NID_sha1, data, strlen(data), sigret, &siglen, pkey);
  if (!retval) { ERR_print_errors_fp (stderr); exit (1);  }
  puts (sigret);
  return(0);
}


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

Reply via email to