1 /* Simple S/MIME decryption example */
2 #include <openssl/pem.h>
3 #include <openssl/cms.h>
4 #include <openssl/err.h>
6 int main(int argc
, char **argv
)
8 BIO
*in
= NULL
, *out
= NULL
, *tbio
= NULL
;
10 EVP_PKEY
*rkey
= NULL
;
11 CMS_ContentInfo
*cms
= NULL
;
14 OpenSSL_add_all_algorithms();
15 ERR_load_crypto_strings();
17 /* Read in recipient certificate and private key */
18 tbio
= BIO_new_file("signer.pem", "r");
23 rcert
= PEM_read_bio_X509(tbio
, NULL
, 0, NULL
);
27 rkey
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
32 /* Open S/MIME message to decrypt */
34 in
= BIO_new_file("smencr.txt", "r");
40 cms
= SMIME_read_CMS(in
, NULL
);
45 out
= BIO_new_file("decout.txt", "w");
49 /* Decrypt S/MIME message */
50 if (!CMS_decrypt(cms
, rkey
, rcert
, NULL
, out
, 0))
58 fprintf(stderr
, "Error Decrypting Data\n");
59 ERR_print_errors_fp(stderr
);
63 CMS_ContentInfo_free(cms
);