在Java 8中,选项-importpassword已添加到keytool。它适用于JKECS商店类型: $ keytool -importpassword -storetype JCEKS -alias别名 输入要存储的密码: 重新输入密码:
$keytool -list -storetype JCEKS -keypass "" -keystore mystore.jceks
Keystore type: JCEKS
Keystore provider: SunJCE
Your keystore contains 1 entry
alias, Apr 7, 2016, SecretKeyEntry,
尝试提取它,我收到错误:
keytool error: java.lang.Exception: Alias <alias> has no certificate
我的问题是:如何提取密码?
答案 0 :(得分:2)
看起来keytool
缺乏提取/导出使用-importpass
命令导入的密码的功能。但是您可以使用KeyStore
api查看密码,使用以下代码:
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()));