Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 显示密钥库证书中的别名密码_Java_Security - Fatal编程技术网

Java 显示密钥库证书中的别名密码

Java 显示密钥库证书中的别名密码,java,security,Java,Security,我使用下面的代码显示与密钥库证书关联的别名,它工作正常,现在如何显示别名passowrd?有什么方法可以做到这一点。 public class keyaliasfinder { public static void main(String args[]) { FileInputStream is = null; try { File file = new File("c:\\my_keystore");

我使用下面的代码显示与密钥库证书关联的别名,它工作正常,现在如何显示别名passowrd?有什么方法可以做到这一点。

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();
                }
        }
    }
}

我对你的问题有点困惑。如果您试图检索别名密码,则该密码不作为明文密码存在。密码用于通过基于密码的派生函数生成加密密钥,密钥用于保护您的私钥。但是,如果您正在寻找一个API来传递别名密码,那么一旦您使用密钥库密码加载密钥库(这就是您所做的),您就可以按如下方式传递别名密码

Key privateKey = keystore.getKey(String alias, char[] aliasPassword)

KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(aliasPassword);

//Get my private key
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)ks.getEntry("privateKeyAlias", protParam);
PrivateKey myPrivateKey = pkEntry.getPrivateKey();

必须提供用于从密钥存储读取私钥的密码。你必须知道这一点。它不存储在密钥存储库中。@Robert,但是我在哪里提到这个密码?你说的是已经存在的密钥存储库密码吗。@Robert,它当然存储在密钥存储库中。但是当然没有API来检索它。否则密钥库API将不安全。@EJP因此目前无法检索回密码?这就是密钥存储的目的-安全地存储密钥,以便只有知道密码的人才能使用密钥。我正在尝试重新检索别名密码,正如您所提到的,同一个密码并不存在明文密码,是否有任何解决方法或破解方法,以及取回密码所需的数据是什么