5 PKCS12_newpass - change the password of a PKCS12 structure
9 #include <openssl/pkcs12.h>
11 int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass);
15 PKCS12_newpass() changes the password of a PKCS12 structure.
17 B<p12> is a pointer to a PKCS12 structure. B<oldpass> is the existing password
18 and B<newpass> is the new password.
22 PKCS12_newpass() returns 1 on success or 0 on failure. Applications can
23 retrieve the most recent error from PKCS12_newpass() with ERR_get_error().
27 This example loads a PKCS#12 file, changes its password and writes out
28 the result to a new file.
32 #include <openssl/pem.h>
33 #include <openssl/err.h>
34 #include <openssl/pkcs12.h>
36 int main(int argc, char **argv)
41 fprintf(stderr, "Usage: pkread p12file password newpass opfile\n");
44 if ((fp = fopen(argv[1], "rb")) == NULL) {
45 fprintf(stderr, "Error opening file %s\n", argv[1]);
48 p12 = d2i_PKCS12_fp(fp, NULL);
51 fprintf(stderr, "Error reading PKCS#12 file\n");
52 ERR_print_errors_fp(stderr);
55 if (PKCS12_newpass(p12, argv[2], argv[3]) == 0) {
56 fprintf(stderr, "Error changing password\n");
57 ERR_print_errors_fp(stderr);
61 if ((fp = fopen(argv[4], "wb")) == NULL) {
62 fprintf(stderr, "Error opening file %s\n", argv[4]);
66 i2d_PKCS12_fp(fp, p12);
75 If the PKCS#12 structure does not have a password, then you must use the empty
76 string "" for B<oldpass>. Using NULL for B<oldpass> will result in a
77 PKCS12_newpass() failure.
79 If the wrong password is used for B<oldpass> then the function will fail,
80 with a MAC verification error. In rare cases the PKCS12 structure does not
81 contain a MAC: in this case it will usually fail with a decryption padding
86 The password format is a NULL terminated ASCII string which is converted to
87 Unicode form internally. As a result some passwords cannot be supplied to
92 L<PKCS12_create(3)>, L<ERR_get_error(3)>