admin管理员组

文章数量:1279237

I am trying to load a private key and a certificate bundled in a PKCS12 file using Java's Keystore#load. The PKCS12 file uses no password and is intended for two-way TLS connections (TLS client-authentication).

The documentation for Keystore#load describes the parameter password as follows:

password - the password used to check the integrity of the keystore, the password used to unlock the keystore, or null.

I interpreted passing null to be the correct choice when loading a PKCS12 file with no password.

On executing the following code, I expected both the private key and the certificate to be loaded into keyStore:

keyStore.load(pkcs12InputStream, null)

However, only the private key is loaded as can be seen by executing the following code after the load operation above:

keyStore.getCertificateChain("1") // or, the custom alias

which returns null

What is the correct way to load both the private key and the certificate using Keystore#load for a PKCS12 file with no password?

I am trying to load a private key and a certificate bundled in a PKCS12 file using Java's Keystore#load. The PKCS12 file uses no password and is intended for two-way TLS connections (TLS client-authentication).

The documentation for Keystore#load describes the parameter password as follows:

password - the password used to check the integrity of the keystore, the password used to unlock the keystore, or null.

I interpreted passing null to be the correct choice when loading a PKCS12 file with no password.

On executing the following code, I expected both the private key and the certificate to be loaded into keyStore:

keyStore.load(pkcs12InputStream, null)

However, only the private key is loaded as can be seen by executing the following code after the load operation above:

keyStore.getCertificateChain("1") // or, the custom alias

which returns null

What is the correct way to load both the private key and the certificate using Keystore#load for a PKCS12 file with no password?

Share Improve this question edited Feb 25 at 3:13 ZarakshR asked Feb 25 at 2:34 ZarakshRZarakshR 1,5811 gold badge8 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Keystore#load expects the value of password to be an empty character array (i.e., new char[0]) when the PKCS12 file uses no password.

It is unclear from the documentation what the purpose of passing null as the value of password is.

本文标签: