/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/languages/C/Samples/openssl/check_rsa.c

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
 
 
4
#include <openssl/pem.h>
 
5
#include <openssl/x509.h>
 
6
 
 
7
 
 
8
main() {
 
9
        int res;
 
10
        FILE *f1, *f2;
 
11
        BIGNUM *a, *b;
 
12
        RSA *key=NULL;
 
13
        X509 *x509=NULL;
 
14
        EVP_PKEY *pkey=NULL;
 
15
        
 
16
        f1=fopen("csa.crt","r");
 
17
        f2=fopen("csa.key","r");
 
18
        
 
19
        PEM_read_X509(f1,&x509,NULL,NULL);
 
20
        pkey=X509_get_pubkey(x509);
 
21
        key=EVP_PKEY_get1_RSA(pkey);
 
22
        EVP_PKEY_free(pkey);
 
23
        X509_free(x509);
 
24
        
 
25
        if (!key) puts("Ooops");
 
26
        
 
27
        a=BN_dup(key->n);
 
28
        b=BN_dup(key->e);
 
29
        PEM_read_RSAPrivateKey(f2,&key,NULL,NULL);
 
30
        if (RSA_check_key(key)) {
 
31
            if ((!BN_cmp(a,key->n))&&(!BN_cmp(b,key->e))) res=1;
 
32
            else res=0;
 
33
        } else res=0;
 
34
        BN_free(a);
 
35
        BN_free(b);
 
36
        RSA_free(key);
 
37
 
 
38
        fclose(f1);
 
39
        fclose(f2);
 
40
 
 
41
        printf("Result: %i\n",res);
 
42
}