栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

初始化后如何完成SunPKCS11 Provider?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

初始化后如何完成SunPKCS11 Provider?

终于能够找到解决方案。Sun的提供程序在下面使用包装器。因此,诀窍是使用Sun的PKCS#11包装器来获取当前实例并完成该实例。显然,此会话功能的最终确定未在提供程序中公开。但是有一个解决方法,它看起来像这样:

public static void providerAndWrapperIssue() throws Exception{    final String name = "ANY_NAME";    final String library = "LOCATION OF THE TOKENS DLL/SO";    final String slot = "SLOT NUMBER";    // SUN PKCS#11 Provider -------------------------------------------    StringBuilder builder = new StringBuilder();    builder.append("name=" + name);    builder.append(System.getProperty("line.separator"));    builder.append("library="" + library + """);    builder.append(System.getProperty("line.separator"));    builder.append("slot=" + slot);    ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes());    Provider provider = new sun.security.pkcs11.SunPKCS11(bais);    provider.setProperty("pkcs11LibraryPath", library);    Security.addProvider(provider);    KeyStore ks = KeyStore.getInstance("PKCS11");    ks.load(null, null);    Enumeration<String> aliases = ks.aliases();    while (aliases.hasMoreElements())        System.out.println(aliases.nextElement());    // ====================================    // Solved it using the SUN PKCS#11 Wrapper    PKCS11 pkcs11 = PKCS11.getInstance(((sun.security.pkcs11.SunPKCS11) provider).getProperty("pkcs11LibraryPath"), null, null, true);    pkcs11.C_Finalize(PKCS11Constants.NULL_PTR);    // ====================================    // IAIK PKCS#11 Wrapper -------------------------------------------    Module pkcs11Module = Module.getInstance(library, false);    pkcs11Module.initialize(null);    Slot[] slots = pkcs11Module.getSlotList(true);    Session session = slots[0].getToken().openSession(true, true, null, null);    session.login(Session.UserType.USER, "".toCharArray());    session.logout();    session.closeSession();    slots[0].getToken().closeAllSessions();    pkcs11Module.finalize(null);}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388467.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号