Advertisement
phr3ncj

rsa_generate_key_example.c

Jan 29th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <openssl/bn.h>
  4. #include <openssl/rsa.h>
  5.  
  6. int main()
  7. {
  8.     RSA *r;
  9.  
  10.     r = RSA_generate_key(2048,RSA_F4,NULL,NULL);
  11.  
  12.     if( r==NULL ) {
  13.         printf("Key failed");
  14.         exit(1);
  15.     } else {
  16.         printf("public modulus (n):\n");
  17.         printf("   %s\n",BN_bn2hex(r->n));
  18.  
  19.         printf("public exponent (e):\n");
  20.         printf("   %s\n",BN_bn2hex(r->e));
  21.  
  22.         printf("private exponent (d):\n");
  23.         printf("   %s\n",BN_bn2hex(r->d));
  24.  
  25.         printf("secret prime factor (p):\n");
  26.         printf("   %s\n",BN_bn2hex(r->p));
  27.         printf("secret prime factor (q):\n");
  28.         printf("   %s\n",BN_bn2hex(r->q));
  29.  
  30.         printf("dmp1 [ d mod (p-1) ]:\n");
  31.         printf("   %s\n",BN_bn2hex(r->dmp1));
  32.         printf("dmq1 [ d mod (q-1) ]:\n");
  33.         printf("   %s\n",BN_bn2hex(r->dmq1));
  34.  
  35.         printf("iqmp [ q^-1 mod p ]:\n");
  36.         printf("   %s\n",BN_bn2hex(r->iqmp));
  37.     }  
  38.  
  39.     printf("RSA SIZE: %d\n", RSA_size(r));
  40.  
  41.     return(0);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement