简体   繁体   English

从智能卡读取证书

[英]read certificate from smartcard

I am trying to read certificates from smart card , 我正在尝试从智能卡读取证书,

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);
                }

    }

}

I got this from http://www.developer.com/java/other/article.php/3587361/Java-Applet-for-Signing-with-a-Smart-Card.htm I will be executing this code in applet, the problem with this is every user has to point me their local pkcs11...dll , does using java samrtcard api can we avoid loading this dll? 我是从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吗? (did not find any examples of loading certificates using java smartcard api) using SunPKCS11 is there any way applet jar can include the dll so that client browser need not provide me (未找到使用java smartcard api加载证书的任何示例)使用SunPKCS11的applet jar可以以任何方式包含dll,以便客户端浏览器无需向我提供

如果使用JWS / JNLP定义小程序,则使用<APPLET>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM