Reputation: 13
In Java 8 the option -importpassword was added to keytool. It works with JKECS storetype: $ keytool -importpassword -storetype JCEKS -alias alias Enter the password to be stored: Re-enter password:
$keytool -list -storetype JCEKS -keypass "" -keystore mystore.jceks
Keystore type: JCEKS
Keystore provider: SunJCE
Your keystore contains 1 entry
alias, Apr 7, 2016, SecretKeyEntry,
Trying to extract it, I get the error:
keytool error: java.lang.Exception: Alias <alias> has no certificate
My question is: How do I extract the password?
Upvotes: 1
Views: 1708
Reputation: 4840
Looks like the keytool
is lacking the capability to extract/export the password imported using the -importpass
command. But you can view the password using KeyStore
api, using the below code:
KeyStore ks = KeyStore.getInstance("JCEKS");
ks.load(new FileInputStream(new File("KEYSTORE_FILE")), "KEYSTORE_PASSWORD".toCharArray());
SecretKey passwordKey = (SecretKey) ks.getKey("ALIAS", "KEY_PASSWORD".toCharArray());
System.out.println(new String(passwordKey.getEncoded()));
Upvotes: 2