1 /* S/MIME signing example: 2 signers. OpenSSL 0.9.9 only */
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
;
9 X509
*scert
= NULL
, *scert2
= NULL
;
10 EVP_PKEY
*skey
= NULL
, *skey2
= NULL
;
14 OpenSSL_add_all_algorithms();
15 ERR_load_crypto_strings();
17 tbio
= BIO_new_file("signer.pem", "r");
22 scert
= PEM_read_bio_X509(tbio
, NULL
, 0, NULL
);
26 skey
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
30 tbio
= BIO_new_file("signer2.pem", "r");
35 scert2
= PEM_read_bio_X509(tbio
, NULL
, 0, NULL
);
39 skey2
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
41 if (!scert2
|| !skey2
)
44 in
= BIO_new_file("sign.txt", "r");
49 p7
= PKCS7_sign(NULL
, NULL
, NULL
, in
, PKCS7_STREAM
| PKCS7_PARTIAL
);
54 /* Add each signer in turn */
56 if (!PKCS7_sign_add_signer(p7
, scert
, skey
, NULL
, 0))
59 if (!PKCS7_sign_add_signer(p7
, scert2
, skey2
, NULL
, 0))
62 out
= BIO_new_file("smout.txt", "w");
66 /* NB: content included and finalized by SMIME_write_PKCS7 */
68 if (!SMIME_write_PKCS7(out
, p7
, in
, PKCS7_STREAM
))
76 fprintf(stderr
, "Error Signing Data\n");
77 ERR_print_errors_fp(stderr
);