| Please read the README file for condition of use, before |
| Maurice Gittens <mgittens@gits.nl> January 1997 |
| #include <openssl/objects.h> |
| #include <openssl/x509.h> |
| #define PUBFILE "cert.pem" |
| #define PRIVFILE "privkey.pem" |
| char *ct = "This the clear text"; |
| ERR_load_crypto_strings(); |
| privKey = ReadPrivateKey(PRIVFILE); |
| ERR_print_errors_fp (stderr); |
| pubKey = ReadPublicKey(PUBFILE); |
| fprintf(stderr,"Error: can't load public key"); |
| buf = malloc(EVP_PKEY_size(pubKey)); |
| buf2 = malloc(EVP_PKEY_size(pubKey)); |
| len = RSA_public_encrypt(strlen(ct)+1, ct, buf, pubKey->pkey.rsa,RSA_PKCS1_PADDING); |
| if (len != EVP_PKEY_size(pubKey)) |
| fprintf(stderr,"Error: ciphertext should match length of key\n"); |
| RSA_private_decrypt(len, buf, buf2, privKey->pkey.rsa,RSA_PKCS1_PADDING); |