I'm trying to import a PKCS12 certificate into a Keystore:
KeyStore keyStore = KeyStore.getInstance( "PKCS12" );
keyStore.load( new FileInputStream( "/tmp/client.p12" ), "changeit".toCharArray() );
This code yields the exception below:
Exception in thread "main" java.io.IOException: DER input, Integer tag error
at sun.security.util.DerInputStream.getInteger(DerInputStream.java:151)
at com.sun.net.ssl.internal.ssl.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1195)
at java.security.KeyStore.load(KeyStore.java:1150)
$ java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
jason@powerpull.net - 07 Dec 2004 06:42 GMT
I'm posting an answer to my own question. The problem was that the file
was not in .p12 format.
By the way, the openssl command is handy for converting certificates
from one format to another.
> I'm trying to import a PKCS12 certificate into a Keystore:
>
[quoted text clipped - 6 lines]
> at sun.security.util.DerInputStream.getInteger(DerInputStream.java:151)
> at
com.sun.net.ssl.internal.ssl.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1195)
> at java.security.KeyStore.load(KeyStore.java:1150)
>
> $ java -version
> java version "1.5.0"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
> Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)