Topic
  • No replies
skorpionking
skorpionking
1 Post

Pinned topic Access to Keystore

‏2013-06-12T12:49:35Z |

Hello togehter,

i have a SmartCard, which includes Certificates. These certificates are accessible via a KeyStore.
My target is to read the certificates.

The access with the SUN-JDK (32-Bit) works like this:

java.security.Provider provider = new sun.security.pkcs11.SunPKCS11( PATH_TO_CFG_FILE );
Security.addProvider( provider );
KeyStore keyStore = KeyStore.getInstance( "PKCS11", provider );
keyStore.load( null, PIN.toCharArray() );
 

Enumeration aliasesEnum = keyStore.aliases();

Java Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
java.security.Provider provider = new sun.security.pkcs11.SunPKCS11( PATH );
Security.addProvider( provider );
KeyStore keyStore = KeyStore.getInstance( "PKCS11", provider );
keyStore.load( null, PIN.toCharArray() );
 
Enumeration aliasesEnum = keyStore.aliases();
while ( aliasesEnum.hasMoreElements() )
{
     String alias = (String) aliasesEnum.nextElement();
     System.out.println( "Alias: " + alias );
     Certificate cert = keyStore.getCertificate( alias );
     System.out.println( "Certificate: " + cert );
     PrivateKey privateKey = (PrivateKey) keyStore.getKey( alias, null );
     System.out.println( "Private key: " + privateKey );
}

But instead of SUN-JDK, I have to use the IBM-JDK.
The access via IBM-JDK should work like this:

Java Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
com.ibm.crypto.pkcs11impl.provider.IBMPKCS11Impl provider = new com.ibm.crypto.pkcs11impl.provider.IBMPKCS11Impl( PATH_TO_CFG_FILE );
Security.insertProviderAt( provider );
KeyStore keyStore = KeyStore.getInstance( "PKCS11IMPLKS", provider );
keyStore.load( null, PIN.toCharArray() );    // <- here occurs the exception
 
Enumeration aliasesEnum = keyStore.aliases();
while ( aliasesEnum.hasMoreElements() )
{
     String alias = (String) aliasesEnum.nextElement();
     System.out.println( "Alias: " + alias );
     Certificate cert = keyStore.getCertificate( alias );
     System.out.println( "Certificate: " + cert );
     PrivateKey privateKey = (PrivateKey) keyStore.getKey( alias, null );
     System.out.println( "Private key: " + privateKey );
}

Unfortunately, I get the following exception in the marked line:

Java Code:
1
2
3
Exception in thread "main" java.security.KeyStoreException: com.ibm.pkcs11.PKCS11Exception: Template is incomplete
    at java.security.KeyStore$Builder$BuilderImpl.getKeyStore(KeyStore.java:707)
...

Can anyone possibly help, who knows what the problem might be?

Best Regards
skorpionking