在Java 8之前,SunPKCS11提供程序的加载方式如下:
Provider provider = new sun.security.pkcs11.SunPKCS11 (new ByteArrayInputStream (configFile.getBytes ()));
Security.addProvider (provider);
Run Code Online (Sandbox Code Playgroud)
configFile
是带有配置参数的String.因此,如果应用程序需要使用多个连接的智能卡,它可以创建多个提供程序.要访问每个提供程序,使用的名称是"SunPKCS11-",后跟我们在配置中指示的名称.
在Java 8中,sun.security.pkcs11.SunPKCS11
该类已在JDK中删除.所以,我不得不通过反思来编程前一个调用.
Java 9中PKCS#11提供程序的操作似乎非常不同:
该SunPKCS11
构造已更改为空单.配置由"configure"方法加载,因此必须将它放在磁盘上的文件中,我不能再通过流将其加载到字符串.
如果我们尝试使用反射,则会出现以下警告:
Run Code Online (Sandbox Code Playgroud)WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by PruebaTarjeta (file:/C:/temp/pkcs11java9/classes/) to constructor sun.security.pkcs11.SunPKCS11() WARNING: Please consider reporting this to the maintainers of PruebaTarjeta WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release