我正在尝试从智能卡读取证书,
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.Security;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
public class Test {
public static void main(String[] args) throws Exception{
Provider pkcs11Provider =new sun.security.pkcs11.SunPKCS11("c:\\dev\\pkcs11.cfg");
char [] pin = {'1', '2', '3', '4'};
KeyStore smartCardKeyStore = KeyStore.getInstance("PKCS11",pkcs11Provider);
smartCardKeyStore.load(null, null);
Enumeration aliasesEnum = smartCardKeyStore.aliases();
while (aliasesEnum.hasMoreElements()) {
String alias = (String)aliasesEnum.nextElement();
System.out.println("Alias: " + alias);
X509Certificate cert =
(X509Certificate) smartCardKeyStore.getCertificate(alias);
System.out.println("Certificate: " + cert);
PrivateKey privateKey =
(PrivateKey) smartCardKeyStore.getKey(alias, null);
System.out.println("Private key: " + privateKey);
}
}
}
我是从http://www.developer.com/java/other/article.php/3587361/Java-Applet-for-Signing-with-a-Smart-Card.htm得到的 我将在applet中执行此代码,问题是每个用户都必须指向我的本地pkcs11 ... dll, 使用java samrtcard api可以避免加载这个dll吗? (没有找到使用java智能卡api加载证书的任何示例) 使用SunPKCS11是否有任何方式applet jar可以包含dll,以便客户端浏览器无需提供我
答案 0 :(得分:1)
如果您使用JWS / JNLP来定义applet,而不是<APPLET>
标记。