2

如何从数字签名电子令牌创建密钥库?如何创建密钥库的路径?如何使用 java 应用程序在任何文档中使用密钥库进行签名?

4

1 回答 1

3

加密硬件设备通常可以通过 PKCS#11 API 进行接口。您将需要 PKCS#11 库(Windows 上的 .dll 或 Unix 上的 .so)充当“设备驱动程序”,通常与设备供应商提供的软件一起安装(请参阅您的电子令牌文档以了解确切的库位置)。您在问题中提到了“密钥库”,因此我猜您使用的是 JAVA 语言,您可以使用 SunPKCS11 提供程序访问 PKCS#11 兼容的加密存储。这是快速示例:

// 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<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
    String alias = aliases.nextElement();
    System.out.println(alias);
}
于 2015-08-29T06:48:21.627 回答