1PKCS12_NEWPASS(3ossl)               OpenSSL              PKCS12_NEWPASS(3ossl)
2
3
4

NAME

6       PKCS12_newpass - change the password of a PKCS12 structure
7

SYNOPSIS

9        #include <openssl/pkcs12.h>
10
11        int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
12

DESCRIPTION

14       PKCS12_newpass() changes the password of a PKCS12 structure.
15
16       p12 is a pointer to a PKCS12 structure. oldpass is the existing
17       password and newpass is the new password.
18
19       Each of oldpass and newpass is independently interpreted as a string in
20       the UTF-8 encoding. If it is not valid UTF-8, it is assumed to be
21       ISO8859-1 instead.
22
23       In particular, this means that passwords in the locale character set
24       (or code page on Windows) must potentially be converted to UTF-8 before
25       use. This may include passwords from local text files, or input from
26       the terminal or command line. Refer to the documentation of
27       UI_OpenSSL(3), for example.
28
29       If the PKCS#12 structure does not have a password, then you must use
30       the empty string "" for oldpass. Using NULL for oldpass will result in
31       a PKCS12_newpass() failure.
32
33       If the wrong password is used for oldpass then the function will fail,
34       with a MAC verification error. In rare cases the PKCS12 structure does
35       not contain a MAC: in this case it will usually fail with a decryption
36       padding error.
37

RETURN VALUES

39       PKCS12_newpass() returns 1 on success or 0 on failure. Applications can
40       retrieve the most recent error from PKCS12_newpass() with
41       ERR_get_error().
42

EXAMPLES

44       This example loads a PKCS#12 file, changes its password and writes out
45       the result to a new file.
46
47        #include <stdio.h>
48        #include <stdlib.h>
49        #include <openssl/pem.h>
50        #include <openssl/err.h>
51        #include <openssl/pkcs12.h>
52
53        int main(int argc, char **argv)
54        {
55            FILE *fp;
56            PKCS12 *p12;
57
58            if (argc != 5) {
59                fprintf(stderr, "Usage: pkread p12file password newpass opfile\n");
60                return 1;
61            }
62            if ((fp = fopen(argv[1], "rb")) == NULL) {
63                fprintf(stderr, "Error opening file %s\n", argv[1]);
64                return 1;
65            }
66            p12 = d2i_PKCS12_fp(fp, NULL);
67            fclose(fp);
68            if (p12 == NULL) {
69                fprintf(stderr, "Error reading PKCS#12 file\n");
70                ERR_print_errors_fp(stderr);
71                return 1;
72            }
73            if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
74                fprintf(stderr, "Error changing password\n");
75                ERR_print_errors_fp(stderr);
76                PKCS12_free(p12);
77                return 1;
78            }
79            if ((fp = fopen(argv[4], "wb")) == NULL) {
80                fprintf(stderr, "Error opening file %s\n", argv[4]);
81                PKCS12_free(p12);
82                return 1;
83            }
84            i2d_PKCS12_fp(fp, p12);
85            PKCS12_free(p12);
86            fclose(fp);
87            return 0;
88        }
89

BUGS

91       The password format is a NULL terminated ASCII string which is
92       converted to Unicode form internally. As a result some passwords cannot
93       be supplied to this function.
94

SEE ALSO

96       PKCS12_create(3), ERR_get_error(3), passphrase-encoding(7)
97
99       Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
100
101       Licensed under the Apache License 2.0 (the "License").  You may not use
102       this file except in compliance with the License.  You can obtain a copy
103       in the file LICENSE in the source distribution or at
104       <https://www.openssl.org/source/license.html>.
105
106
107
1083.0.9                             2023-07-27             PKCS12_NEWPASS(3ossl)
Impressum