有没有办法使用java以编程方式从etoken中提取证书?
如果是这样,是否可以将其转换为 Java KeyStore(.jks) 文件?
这是我的代码
String alias;
SunPKCS11 sunpkcs11;
Key privateKey;
String cfgFile = "D:\\cfgFile.cfg";
sunpkcs11 = new SunPKCS11(cfgFile);
Security.addProvider(sunpkcs11);
alias = "myAlias";
KeyStore.Builder builderRunning = KeyStore.Builder.newInstance("PKCS11", sunpkcs11,new KeyStore.CallbackHandlerProtection(new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
}}));
KeyStore keyStore = builder.getKeyStore();
// get my private key
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias,
new KeyStore.PasswordProtection("password".toCharArray()));
privateKey = pkEntry.getPrivateKey();
它返回一个空指针异常。我对此很陌生,不知道如何进一步进行。