1 /* Simple S/MIME signing example */
2 #include <openssl/pem.h>
3 #include <openssl/pkcs7.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
;
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 content being signed */
34 in
= BIO_new_file("smencr.txt", "r");
40 p7
= SMIME_read_PKCS7(in
, NULL
);
45 out
= BIO_new_file("encrout.txt", "w");
49 /* Decrypt S/MIME message */
50 if (!PKCS7_decrypt(p7
, rkey
, rcert
, out
, 0))
58 fprintf(stderr
, "Error Signing Data\n");
59 ERR_print_errors_fp(stderr
);