在Java 8之前,SunPKCS11提供程序是这样加载的:
Provider provider = new sun.security.pkcs11.SunPKCS11 (new ByteArrayInputStream (configFile.getBytes ()));
Security.addProvider (provider);
configFile
是一个包含配置参数的字符串。因此,如果应用程序需要使用多个连接的智能卡,则可以创建多个提供程序。要访问每个提供程序,使用的名称为"SunPKCS11-",后跟我们在配置中指定的名称。
在Java 8中,sun.security.pkcs11.SunPKCS11
类已从JDK中删除。因此,我必须通过反射编写先前的调用。
Java 9中的PKCS#11提供程序的操作似乎非常不同:
SunPKCS11
构造函数已更改为空构造函数。配置由"configure"方法加载,因此必须将其放在磁盘上的文件中,我不能再通过流加载它到字符串中。如果尝试使用反射,则会出现以下警告:
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
在Java 9中,会自动生成一个SunPKCS11提供程序并将其列入加密提供程序列表。可以从列表中获取并进行配置。问题在于,列表中只能加载一个PKCS#11提供程序。Java 9文档指出我们可以通过“SunPKCS11-”后跟我们在配置中指定的名称来获取PKCS#11提供程序,但这是不正确的。如果查看提供程序列表,唯一的提供程序是“SunPKCS11”,因此我无法为每张智能卡设置一个提供程序。你遇到过类似的问题吗?有解决方案吗?
--illegal-access=permit
吗? - Naman