5 #include <openssl/pem.h>
6 #include <openssl/err.h>
7 #include <openssl/pkcs12.h>
9 /* Simple PKCS#12 file creator */
11 int main(int argc
, char **argv
)
18 fprintf(stderr
, "Usage: pkwrite infile password name p12file\n");
21 SSLeay_add_all_algorithms();
22 ERR_load_crypto_strings();
23 if (!(fp
= fopen(argv
[1], "r"))) {
24 fprintf(stderr
, "Error opening file %s\n", argv
[1]);
27 cert
= PEM_read_X509(fp
, NULL
, NULL
, NULL
);
29 pkey
= PEM_read_PrivateKey(fp
, NULL
, NULL
, NULL
);
31 p12
= PKCS12_create(argv
[2], argv
[3], pkey
, cert
, NULL
, 0,0,0,0,0);
33 fprintf(stderr
, "Error creating PKCS#12 structure\n");
34 ERR_print_errors_fp(stderr
);
37 if (!(fp
= fopen(argv
[4], "wb"))) {
38 fprintf(stderr
, "Error opening file %s\n", argv
[1]);
39 ERR_print_errors_fp(stderr
);
42 i2d_PKCS12_fp(fp
, p12
);