Java nssdb连接:无法初始化NSS

时间:2018-05-22 14:33:05

标签: java keystore pkcs#11 nss

我正在尝试使用Java从nss db中提取证书数据。这是我的代码:

try {
        char[] password = new char[0];
        Provider nss = new sun.security.pkcs11.SunPKCS11("C:\\ntdps_temp\\proj\\NSSdb\\scripts\\pkcs11.cfg");
        Security.addProvider(nss);
        KeyStore ks = KeyStore.getInstance("PKCS11", nss);
        ks.load(null, password);
        for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements();) {
            System.out.println(aliases.nextElement());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

这是pkcs11.cfg:

name = NSSdb
nssModule = keystore
nssDbMode = readWrite
nssLibraryDirectory = C:\ntdps_temp\proj\NSSdb\lib
nssSecmodDirectory = C:\ntdps_temp\proj\NSSdb

这是我的堆栈跟踪:

java.security.ProviderException: Could not initialize NSS
        at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:212)
        at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
        at exportnssdb.ExportNssDb.main(ExportNssDb.java:30)
Caused by: java.io.IOException: The specified module could not be found.

        at sun.security.pkcs11.Secmod.nssLoadLibrary(Native Method)
        at sun.security.pkcs11.Secmod.initialize(Secmod.java:210)
        at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:207)
        ... 2 more

注意第30行引用此处的Provider nss = new sun.security.pkcs11.SunPKCS11("C:\\ntdps_temp\\proj\\NSSdb\\scripts\\pkcs11.cfg");

我正在为这个特定的程序运行32位Java。在此先感谢您的任何帮助

0 个答案:

没有答案