0

我正在尝试使用 Java(和 BouncyCastle)创建一个 PKCS 12(P12)文件。出于某种原因,我的代码没有将我的密码添加到我添加到 p12 文件的密钥条目中。

p12 文件本身的密码有效。但是,不会添加特定密钥条目的密码。

我的代码:

        // open the file 
        fileName = "my_output.p12";
        OutputStream outFile = new FileOutputStream (fileName);

        // get privatekey and cert details ...
        // ...

        // initialize 
        // note: I have also tried:  KeyStore.getInstance("PKCS12", "BC");
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        keyStore.load(null, null);

        // this line doesn't add my password "test_pass" !
        keyStore.setKeyEntry("test_alias", myExistingPrivateKey, "key_pass".toCharArray(), myExistingCertChain);  


        // store keystore and close file
        keyStore.store(outFile, "container_pass".toCharArray());
        outFile.close();

请注意,当容器类型是 JKS 而不是 PKCS12 时,相同的代码可以正常工作

4

0 回答 0