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";
38 ERR_load_crypto_strings();
40 privKey = ReadPrivateKey(PRIVFILE);
43 ERR_print_errors_fp (stderr);
47 pubKey = ReadPublicKey(PUBFILE);
50 EVP_PKEY_free(privKey);
51 fprintf(stderr,"Error: can't load public key");
55 /* No error checking */
56 buf = malloc(EVP_PKEY_size(pubKey));
57 buf2 = malloc(EVP_PKEY_size(pubKey));
59 len = RSA_public_encrypt(strlen(ct)+1, ct, buf, pubKey->pkey.rsa,RSA_PKCS1_PADDING);
61 if (len != EVP_PKEY_size(pubKey))
63 fprintf(stderr,"Error: ciphertext should match length of key\n");
67 RSA_private_decrypt(len, buf, buf2, privKey->pkey.rsa,RSA_PKCS1_PADDING);
71 EVP_PKEY_free(privKey);
72 EVP_PKEY_free(pubKey);