I'm trying to load a keystore from a pfx file, but when i try to upload a pfx file and load the keystore with the code below, it gave me a NullPointerException. The password and the my baos (ByteArrayOutputStream) are not null. Any idea what might be happening?
KeyStore ks = KeyStore.getInstance("PKCS12");
String passw = passwordField.getValue();
ks.load(new ByteArrayInputStream(baos.toByteArray()), passw.toCharArray());
This code works with a lot of certificates, but in a specific pfx file this is gaving me this problem:
java.lang.NullPointerException
at java.lang.String.<init>(String.java:491)
at sun.security.pkcs12.PKCS12KeyStore.loadSafeContents(PKCS12KeyStore.java:2286)
at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2025)
at java.security.KeyStore.load(KeyStore.java:1445)
Thanks.
I had the same problem few days ago. In my case the problem was the pfx file that was exported without/wrongly the certificate itself and the private key. It just contained the public key chain of trust.
The solution was to export again the pfx file.
Check your pfx file with this program in Windows (from Kent Chen article): https://www.nextofwindows.com/how-to-check-a-pfx-certifications-expiry-date-on-windows
Or in linux use:
openssl pkcs12 -info -in certificate_name.p12