Managing Microsoft Crypto API credentials

The toolkit grants access to keys and certificates in Microsoft Crypto API (CAPI) stores.

Installing the Microsoft Crypto API library

Download the etjava90lib.zip file from trustedcare.entrust.com. This file contains the following dynamic link library for managing Microsoft Crypto API credentials.

jnicapi_64.dll

Install the library in the following folder.

%windir%\SysWOW64

Creating the user

Instantiate a User object.

com.entrust.toolkit.User user = new User();

Listing users

List and display all available CAPI users.

com.entrust.toolkit.credentials.CapiIdentities identities = CapiIdentities.findIdentities();
System.out.println("Number of identities found: " + identities.size());
int index = 1;
Iterator iterator = identities.iterator();
while (iterator.hasNext())
{
CapiIdentity identity = (CapiIdentity) iterator.next();
System.out.println(index + ". " + identity.getDistinguishedName());
++index;
}

Selecting the user

Prompt for the identity to log in to.

System.out.println("Enter index of identity to log in to: ");
byte[] b = new byte[5];
try
{
System.in.read(b);
index = Integer.parseInt(new String(b).trim());
}
catch (IOException e)
{
System.out.println("Error reading, will use first identity");
index = 1;
}

Go through the identities to choose the selected identity.

if (index > 0 && index <= identities.size())
{
iterator = identities.iterator();
while (--index > 0)
{
iterator.next();
}
CapiIdentity identity = (CapiIdentity) iterator.next();
}

Reading key and certificates

Instantiate a reader to read the keys and certificates from CAPI.

com.entrust.toolkit.credentials.CapiCredentialReader credReader = new CapiCredentialReader(identity);

Logging the user

Log in the user with the selected credentials.

user.login(credReader, <password>);