Hello,
If your vendor has only supplied you with an MS CAPI driver, then you can just install the driver and use JCAPI as usual. You don't have to add the CSP explicitly for JCAPI in this case (this is only required for PKCS#11 CSPs).
the private key is not exportable, and suppose i know the alias is:
aaaaaaaaaa
Your given alias is not a valid JCAPI alias. Please see the example code below for an explanation.
can you provide an example that proved how to use jcapi to generate the signature with CallbackforPIN module?
What's a
CallbackforPIN module?
If you mean the
JCAPIPINCallback interface, then you have to add a PKCS#11 driver for your hardware token into JCAPI. Otherwise the CSP's own native PIN code dialog will be shown instead of the Java Swing based one provided by JCAPI.
I'm a bit surprised that your vendor has not supplied you with a PKCS#11 DLL. If you want to use your own Java based PIN code callback for your hardware key, then you have to use a PKCS#11 DLL for your key with JCAPI. Ask your vendor for such a driver.
Ok, here's an example of how to create a signature with JCAPI:
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import com.pheox.jcapi.*;
public class SignTest
{
static public void main(String[] args)
{
try {
Security.addProvider(new JCAPIProvider());
//Init JCAPI key store.
KeyStore ks = KeyStore.getInstance("msks", "JCAPI");
ks.load(null, null);
//Sign data using JCAPI.
byte[] dataToSign = {1,2,3,4,5};
Signature s = Signature.getInstance("SHA1withRSA", "JCAPI");
//The alias below will not work since a JCAPI alias is built
//from <system store name>|<base 64 encoded hash value of certificate>
//For example: MY|dTrrUZrdV/ULrLFH7iqLdFUKNOA=
String alias = "aaaaaaaaaa";
RSAPrivateKey privateKey = (RSAPrivateKey)ks.getKey(alias, null);
if(privateKey == null)
throw new Exception("No private key found for given alias.");
s.initSign(privateKey);
s.update(dataToSign);
byte[] signature = s.sign();
System.out.println("Signature = " + new String(signature));
} catch(Throwable t) {
t.printStackTrace();
System.err.println("Test prog failed. Exiting...");
}
}
}
Did this answear your questions? If not, please provide some more detailed information about what you want to achieve and I'll try to get you some good answears
Regards,
Tommy