xref: /openssl/doc/man3/PKCS12_add_cert.pod (revision c7d848e2)
1=pod
2
3=head1 NAME
4
5PKCS12_add_cert, PKCS12_add_key, PKCS12_add_key_ex,
6PKCS12_add_secret - Add an object to a set of PKCS#12 safeBags
7
8=head1 SYNOPSIS
9
10 #include <openssl/pkcs12.h>
11
12 PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
13 PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags,
14                               EVP_PKEY *key, int key_usage, int iter,
15                               int key_nid, const char *pass);
16 PKCS12_SAFEBAG *PKCS12_add_key_ex(STACK_OF(PKCS12_SAFEBAG) **pbags,
17                                   EVP_PKEY *key, int key_usage, int iter,
18                                   int key_nid, const char *pass,
19                                   OSSL_LIB_CTX *ctx, const char *propq);
20
21 PKCS12_SAFEBAG *PKCS12_add_secret(STACK_OF(PKCS12_SAFEBAG) **pbags,
22                                  int nid_type, const unsigned char *value, int len);
23
24=head1 DESCRIPTION
25
26These functions create a new B<PKCS12_SAFEBAG> and add it to the set of safeBags
27in I<pbags>.
28
29PKCS12_add_cert() creates a PKCS#12 certBag containing the supplied
30certificate and adds this to the set of PKCS#12 safeBags.
31
32PKCS12_add_key() creates a PKCS#12 keyBag (unencrypted) or a pkcs8shroudedKeyBag
33(encrypted) containing the supplied B<EVP_PKEY> and adds this to the set of PKCS#12
34safeBags. If I<key_nid> is not -1 then the key is encrypted with the supplied
35algorithm, using I<pass> as the passphrase and I<iter> as the iteration count. If
36I<iter> is zero then a default value for iteration count of 2048 is used.
37
38PKCS12_add_key_ex() is identical to PKCS12_add_key() but allows for a library
39context I<ctx> and property query I<propq> to be used to select algorithm
40implementations.
41
42PKCS12_add_secret() creates a PKCS#12 secretBag with an OID corresponding to
43the supplied I<nid_type> containing the supplied value as an ASN1 octet string.
44This is then added to the set of PKCS#12 safeBags.
45
46=head1 NOTES
47
48If a certificate contains an I<alias> or a I<keyid> then this will be
49used for the corresponding B<friendlyName> or B<localKeyID> in the
50PKCS12 structure.
51
52PKCS12_add_key() makes assumptions regarding the encoding of the given pass
53phrase.
54See L<passphrase-encoding(7)> for more information.
55
56=head1 RETURN VALUES
57
58A valid B<PKCS12_SAFEBAG> structure or NULL if an error occurred.
59
60=head1 CONFORMING TO
61
62IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
63
64=head1 SEE ALSO
65
66L<PKCS12_create(3)>
67
68=head1 HISTORY
69
70PKCS12_add_secret() and PKCS12_add_key_ex() were added in OpenSSL 3.0.
71
72=head1 COPYRIGHT
73
74Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
75
76Licensed under the Apache License 2.0 (the "License").  You may not use
77this file except in compliance with the License.  You can obtain a copy
78in the file LICENSE in the source distribution or at
79L<https://www.openssl.org/source/license.html>.
80
81=cut
82