java代码生成密钥库,使用Java从数字签名电子令牌生成密钥库

这篇博客介绍了如何通过Java应用程序利用PKCS#11 API与数字签名电子令牌(e-token)进行交互。首先,你需要找到设备供应商提供的PKCS#11库(如.dll或.so文件)。然后,使用SunPKCS11提供程序来创建并加载密钥库,并用PIN码登录。最后,可以遍历并操作密钥库中的证书和私钥。
摘要由CSDN通过智能技术生成

How to create the keystore from digital signature e-token? How crate the path of keystore? How to sign with the keystore in any document using java application?

解决方案

Cryptographic hardware devices can usually be interfaced via PKCS#11 API. You will need PKCS#11 library (.dll on Windows or .so on Unix) acting as a "device driver" which gets usually installed along with the software provided by the device vendor (consult your e-token documentation for the exact library location). You have mentioned "keystore" in your question therefore I guess you are using JAVA language and you can use SunPKCS11 provider to access PKCS#11 compatible cryptographic store. Here is the quick sample:

// Create instance of SunPKCS11 provider

String pkcs11Config = "name=eToken\nlibrary=C:\\path\\to\\your\\pkcs11.dll";

java.io.ByteArrayInputStream pkcs11ConfigStream = new java.io.ByteArrayInputStream(pkcs11Config.getBytes());

sun.security.pkcs11.SunPKCS11 providerPKCS11 = new sun.security.pkcs11.SunPKCS11(pkcs11ConfigStream);

java.security.Security.addProvider(providerPKCS11);

// Get provider KeyStore and login with PIN

String pin = "11111111";

java.security.KeyStore keyStore = java.security.KeyStore.getInstance("PKCS11", providerPKCS11);

keyStore.load(null, pin.toCharArray());

// Enumerate items (certificates and private keys) in the KeyStore

java.util.Enumeration aliases = keyStore.aliases();

while (aliases.hasMoreElements()) {

String alias = aliases.nextElement();

System.out.println(alias);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值