None of the answers on this topic in the forum sufficiently address this problem when recommendations don't work. i.e. I have a application that is processing PKI certs. This app has been working fine until my certificate expired and I had to obtain a new one. I replaced the certificate as follows:
keytool -v -importkeystore -srckeystore cert.p12 -srcstoretype PKCS12 - srcalias [alias name] -destkeystore keystore.jks -deststoretype JKS -deststorepass changeit -destalias [alias name]
When I tried to run app I got the "cannot recover key" exception, which I never got before. So I found the recommendations to run:
keytool -keypasswd -alias [alias name] -keystore keystore.jks
I gave it the store password and the cert password as prompted, but still received the same exception. Now what? I've been experimenting all afternoon and nothing seems to resolve the exception. And the stack trace doesn't provide anymore clues with debug on.
importcertcommand. - always_a_rookieimportkeystore, that will import the private key as well. Ideally what you would do is, create a PKCS#10 (CSR) from the existing private key and send the CSR to your certificate issuer, and get a certificate chain back. And then associate the received certificate chain to the existing private key using theimportcertcommand. - always_a_rookie