root/openpgpsdk/trunk/examples/create-signed-key.c

Revision 138 (checked in by ben, 8 years ago)

Closer to signing, and parse secret key.

Line 
1 #include "create.h"
2 #include "util.h"
3 #include "signature.h"
4 #include <stdio.h>
5
6 int main(int argc,char **argv)
7     {
8     ops_writer_fd_arg_t arg;
9     ops_create_options_t opt;
10     char *user_id;
11     const char *nstr;
12     const char *estr;
13     BIGNUM *n=NULL;
14     BIGNUM *e=NULL;
15     ops_public_key_t key;
16     ops_secret_key_t skey;
17     ops_create_signature_t sig;
18     ops_user_id_t id;
19     unsigned char keyid[OPS_KEY_ID_SIZE];
20
21     if(argc != 2)
22         {
23         fprintf(stderr,"%s <public key file> <secret key file>\n",argv[0]);
24         exit(1);
25         }
26    
27     nstr=argv[1];
28     estr=argv[2];
29     user_id=argv[3];
30
31     BN_hex2bn(&n,nstr);
32     BN_hex2bn(&e,estr);
33
34     arg.fd=1;
35     opt.writer=ops_writer_fd;
36     opt.arg=&arg;
37
38     ops_fast_create_rsa_public_key(&key,time(NULL),n,e);
39     ops_write_struct_public_key(&key,&opt);
40
41     ops_fast_create_user_id(&id,user_id);
42     ops_write_struct_user_id(&id,&opt);
43
44     ops_signature_start(&sig,&key,&id);
45     ops_signature_add_creation_time(&sig,time(NULL));
46
47     ops_keyid(keyid,&key);
48     ops_signature_add_issuer_key_id(&sig,keyid);
49
50     ops_signature_add_primary_user_id(&sig,ops_true);
51
52     ops_signature_hashed_subpackets_end(&sig);
53
54     ops_signature_end(&sig,&key,&skey);
55
56     return 0;
57     }
Note: See TracBrowser for help on using the browser.