Search code examples
sslopenssltls1.2keytool

How to change .p12 password?


I have a .p12 file and I need to change its password. And this new password have to be "1234"

I already tried to do this with Keytool :

keytool -importkeystore -srckeystore authentification.p12 -srcstoretype PKCS12 -srcstorepass "2600807934-Auth" -destkeystore new.p12 -deststoretype PKCS12 -storepass 1234

But i got an error message telling me that the new password must contains at lesat 6 char.

Do you no another way to do this ? (I got other .p12 files with "1234" as password, so it is possible)


Solution

  • You can do this with two subsequent openssl pkcs12 commands. First, to extract your contents from the .p12 file, use

    openssl pkcs12 -in contents.p12 -out contents.txt
    

    It will ask you for the password to access contents.p12 (1234 in your case), as well as a new password for encrypting the private key that ends up in contents.txt (and an additional time to verify you did not make a typo).

    The you can use the following command to re-construct a .p12 from contents.txt:

    openssl pkcs12 -export -in contents.txt -out contents_new.p12
    

    It will ask you for the password that you used to encrypt the private key in the previous step, as well as a new password for the .p12 bundle (and again an additional time to verify you did not make a typo).