我使用下面的代码显示与我的密钥库证书关联的别名,它工作正常,现在如何显示别名密码?有什么方法可以解决这个问题。
public class keyaliasfinder {
public static void main(String args[])
{
FileInputStream is = null;
try {
File file = new File("c:\\my_keystore");
is = new FileInputStream(file);
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
String password = "FnvUKHdr6b4343dfdf";
keystore.load(is, password.toCharArray());
PrivateKey p=new PrivateKey() {
@Override
public String getFormat() {
// TODO Auto-generated method stub
return null;
}
@Override
public byte[] getEncoded() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getAlgorithm() {
// TODO Auto-generated method stub
return null;
}
};
Enumeration enumeration = keystore.aliases();
while(enumeration.hasMoreElements()) {
String alias = (String)enumeration.nextElement();
System.out.println("alias name: " + alias);
Certificate certificate = keystore.getCertificate(alias);
System.out.println(certificate.toString());
}
} catch (java.security.cert.CertificateException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(null != is)
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}