使用Java创建P12(PKCS 12)文件时,无法为ke条目添加密码

时间:2016-10-26 23:08:07

标签: java cryptography bouncycastle keystore pkcs12

我正在尝试使用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时,相同的代码可以正常工作

0 个答案:

没有答案