4 #include <openssl/pem.h>
5 #include <openssl/err.h>
6 #include <openssl/pkcs12.h>
8 /* Simple PKCS#12 file creator */
10 int main(int argc, char **argv)
17 fprintf(stderr, "Usage: pkwrite infile password name p12file\n");
20 OpenSSL_add_all_algorithms();
21 ERR_load_crypto_strings();
22 if ((fp = fopen(argv[1], "r")) == NULL) {
23 fprintf(stderr, "Error opening file %s\n", argv[1]);
26 cert = PEM_read_X509(fp, NULL, NULL, NULL);
28 pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
30 p12 = PKCS12_create(argv[2], argv[3], pkey, cert, NULL, 0, 0, 0, 0, 0);
32 fprintf(stderr, "Error creating PKCS#12 structure\n");
33 ERR_print_errors_fp(stderr);
36 if ((fp = fopen(argv[4], "wb")) == NULL) {
37 fprintf(stderr, "Error opening file %s\n", argv[1]);
38 ERR_print_errors_fp(stderr);
41 i2d_PKCS12_fp(fp, p12);