I am using Aladdin etoken
This is the code that gives me the error :
/**
* Get the private key and its certification chain from the keystore.
* The keystore is considered to have only one entry that contains
* both certification chain and its corresponding private key. If the keystore has
* no entries, an exception is thrown.
* @param aKeyStore ketystore reference
* @return private key and certification chain corresponding to it, extracted from
* given keystore.
* @throws GeneralSecurityException when a problem arise during the smartcard access
*/
private static PrivateKeyAndCertChain getPrivateKeyAndCertChain(
KeyStore aKeyStore)
throws GeneralSecurityException {
Enumeration aliasesEnum = aKeyStore.aliases();
if (aliasesEnum.hasMoreElements()) {
String alias = (String)aliasesEnum.nextElement();
Certificate[] certificationChain = aKeyStore.getCertificateChain(alias);
PrivateKey privateKey = (PrivateKey) aKeyStore.getKey(alias, null);
PrivateKeyAndCertChain result = new PrivateKeyAndCertChain();
result.mPrivateKey = privateKey;
result.mCertificationChain = certificationChain;
return result;
} else {
throw new KeyStoreException("The keystore is empty!");
}
}
Output :
Registering SafeNet provider...
Provider:SunPKCS11-Name using library C:\Windows\System32\eTPKCS11.dll
Can not extract the private key and certificate from the smart card. Reason: The keystore is empty!
It skips the code from if() condition
This program was bundled with the Aladdin etoken SDK.
So I was hoping that maybe there is some mechanism to work around because the code is used to generate a keystore.