【发布时间】:2014-03-13 08:19:23
【问题描述】:
我正在尝试从智能卡读取证书,
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 得到这个 我将在小程序中执行此代码,问题是每个用户都必须向我指出他们的本地 pkcs11...dll , 使用java samrtcard api可以避免加载这个dll吗? (没有找到任何使用 java smartcard api 加载证书的示例) 使用 SunPKCS11 有什么办法可以让 applet jar 包含 dll,这样客户端浏览器就不需要提供我了
【问题讨论】:
-
智能卡在 PKCS#11 之上有 CSP 层,它使其中的所有证书(不是私钥)在您插入后立即在证书存储中可用。您可以通过编写几行代码来使用 Browser Extensions for Modern browsers 进行签名,以使用 Browser Extension 提供的方法。 My Co. 为现代浏览器提供了一个这样的免费Browser Extension。