2 * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include <openssl/pem.h>
13 #include <openssl/err.h>
14 #include <openssl/pkcs12.h>
16 /* Simple PKCS#12 file creator */
18 int main(int argc, char **argv)
25 fprintf(stderr, "Usage: pkwrite infile password name p12file\n");
28 OpenSSL_add_all_algorithms();
29 ERR_load_crypto_strings();
30 if ((fp = fopen(argv[1], "r")) == NULL) {
31 fprintf(stderr, "Error opening file %s\n", argv[1]);
34 cert = PEM_read_X509(fp, NULL, NULL, NULL);
36 pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
38 p12 = PKCS12_create(argv[2], argv[3], pkey, cert, NULL, 0, 0, 0, 0, 0);
40 fprintf(stderr, "Error creating PKCS#12 structure\n");
41 ERR_print_errors_fp(stderr);
44 if ((fp = fopen(argv[4], "wb")) == NULL) {
45 fprintf(stderr, "Error opening file %s\n", argv[1]);
46 ERR_print_errors_fp(stderr);
49 i2d_PKCS12_fp(fp, p12);