| /* Simple S/MIME signing example */ |
| #include <openssl/pkcs7.h> |
| int main(int argc, char **argv) |
| BIO *in = NULL, *out = NULL, *tbio = NULL; |
| OpenSSL_add_all_algorithms(); |
| ERR_load_crypto_strings(); |
| /* Read in recipient certificate and private key */ |
| tbio = BIO_new_file("signer.pem", "r"); |
| rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); |
| rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); |
| /* Open content being signed */ |
| in = BIO_new_file("smencr.txt", "r"); |
| p7 = SMIME_read_PKCS7(in, NULL); |
| out = BIO_new_file("encrout.txt", "w"); |
| /* Decrypt S/MIME message */ |
| if (!PKCS7_decrypt(p7, rkey, rcert, out, 0)) |
| fprintf(stderr, "Error Signing Data\n"); |
| ERR_print_errors_fp(stderr); |