How to access certificate from eToken in java

2019-04-01 15:17发布

I want to read certificate from eToken when it plugged-in, when I store that certificate on local machine I can read it through my java application but, I don't know how to read it from eToken.

RSAPublicKey pub;
            String fileName = "C:\\myCert.cer";

             InputStream inStream = new FileInputStream(fileName);
             CertificateFactory cf = CertificateFactory.getInstance("X.509");
             X509Certificate cert =
        (X509Certificate)cf.generateCertificate(inStream);
             inStream.close();

             pub = (RSAPublicKey) cert.getPublicKey();
             System.out.println(cert.getIssuerDN());
             System.out.println(cert.getSubjectDN());
             System.out.println(cert.getSubjectAlternativeNames());
             byte [] tempPub = pub.getEncoded();
             String sPub = new String( tempPub );

1条回答
我想做一个坏孩纸
2楼-- · 2019-04-01 15:33

One way to do this is by using the PKCS#11 provider. It comes with examples, too.

查看更多
登录 后发表回答