]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/PKCS12_newpass.pod
Update copyright year
[thirdparty/openssl.git] / doc / man3 / PKCS12_newpass.pod
CommitLineData
c95a8b4e
JW
1=pod
2
3=head1 NAME
4
5PKCS12_newpass - change the password of a PKCS12 structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/pkcs12.h>
10
049f5bbc 11 int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
c95a8b4e
JW
12
13=head1 DESCRIPTION
14
15PKCS12_newpass() changes the password of a PKCS12 structure.
16
17B<p12> is a pointer to a PKCS12 structure. B<oldpass> is the existing password
18and B<newpass> is the new password.
19
cff85f39
DW
20=head1 NOTES
21
22Each of B<oldpass> and B<newpass> is independently interpreted as a string in
23the UTF-8 encoding. If it is not valid UTF-8, it is assumed to be ISO8859-1
24instead.
25
26In particular, this means that passwords in the locale character set
27(or code page on Windows) must potentially be converted to UTF-8 before
28use. This may include passwords from local text files, or input from
29the terminal or command line. Refer to the documentation of
30L<UI_OpenSSL(3)>, for example.
31
c95a8b4e
JW
32=head1 RETURN VALUES
33
34PKCS12_newpass() returns 1 on success or 0 on failure. Applications can
35retrieve the most recent error from PKCS12_newpass() with ERR_get_error().
36
40cb2be7 37=head1 EXAMPLES
c95a8b4e
JW
38
39This example loads a PKCS#12 file, changes its password and writes out
40the result to a new file.
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <openssl/pem.h>
45 #include <openssl/err.h>
46 #include <openssl/pkcs12.h>
47
48 int main(int argc, char **argv)
49 {
2947af32
BB
50 FILE *fp;
51 PKCS12 *p12;
e9b77246 52
2947af32
BB
53 if (argc != 5) {
54 fprintf(stderr, "Usage: pkread p12file password newpass opfile\n");
55 return 1;
56 }
57 if ((fp = fopen(argv[1], "rb")) == NULL) {
58 fprintf(stderr, "Error opening file %s\n", argv[1]);
59 return 1;
60 }
61 p12 = d2i_PKCS12_fp(fp, NULL);
62 fclose(fp);
63 if (p12 == NULL) {
64 fprintf(stderr, "Error reading PKCS#12 file\n");
65 ERR_print_errors_fp(stderr);
66 return 1;
67 }
68 if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
69 fprintf(stderr, "Error changing password\n");
70 ERR_print_errors_fp(stderr);
71 PKCS12_free(p12);
72 return 1;
73 }
74 if ((fp = fopen(argv[4], "wb")) == NULL) {
75 fprintf(stderr, "Error opening file %s\n", argv[4]);
76 PKCS12_free(p12);
77 return 1;
78 }
79 i2d_PKCS12_fp(fp, p12);
80 PKCS12_free(p12);
81 fclose(fp);
82 return 0;
c95a8b4e
JW
83 }
84
85
86=head1 NOTES
87
88If the PKCS#12 structure does not have a password, then you must use the empty
89string "" for B<oldpass>. Using NULL for B<oldpass> will result in a
90PKCS12_newpass() failure.
91
92If the wrong password is used for B<oldpass> then the function will fail,
93with a MAC verification error. In rare cases the PKCS12 structure does not
94contain a MAC: in this case it will usually fail with a decryption padding
95error.
96
97=head1 BUGS
98
99The password format is a NULL terminated ASCII string which is converted to
100Unicode form internally. As a result some passwords cannot be supplied to
101this function.
102
103=head1 SEE ALSO
104
84814344
RL
105L<PKCS12_create(3)>, L<ERR_get_error(3)>,
106L<passphrase-encoding(7)>
c95a8b4e 107
e2f92610
RS
108=head1 COPYRIGHT
109
1cb7eff4 110Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
e2f92610
RS
111
112Licensed under the OpenSSL license (the "License"). You may not use
113this file except in compliance with the License. You can obtain a copy
114in the file LICENSE in the source distribution or at
115L<https://www.openssl.org/source/license.html>.
116
117=cut