3 Please read the README file for condition of use, before
6 Maurice Gittens <mgittens@gits.nl> January 1997
13 #include <openssl/rsa.h>
14 #include <openssl/evp.h>
15 #include <openssl/objects.h>
16 #include <openssl/x509.h>
17 #include <openssl/err.h>
18 #include <openssl/pem.h>
19 #include <openssl/ssl.h>
23 #define PUBFILE "cert.pem"
24 #define PRIVFILE "privkey.pem"
30 char *ct = "This the clear text";
37 ERR_load_crypto_strings();
39 privKey = ReadPrivateKey(PRIVFILE);
42 ERR_print_errors_fp (stderr);
46 pubKey = ReadPublicKey(PUBFILE);
49 EVP_PKEY_free(privKey);
50 fprintf(stderr,"Error: can't load public key");
54 /* No error checking */
55 buf = malloc(EVP_PKEY_size(pubKey));
56 buf2 = malloc(EVP_PKEY_size(pubKey));
58 len = RSA_public_encrypt(strlen(ct)+1, ct, buf, pubKey->pkey.rsa,RSA_PKCS1_PADDING);
60 if (len != EVP_PKEY_size(pubKey))
62 fprintf(stderr,"Error: ciphertext should match length of key\n");
66 RSA_private_decrypt(len, buf, buf2, privKey->pkey.rsa,RSA_PKCS1_PADDING);
70 EVP_PKEY_free(privKey);
71 EVP_PKEY_free(pubKey);