class sun.security.pkcs11.SunPKCS11 上的错误
Error on class sun.security.pkcs11.SunPKCS11
我使用此代码在 java1.4 中创建了 keyStore。
`public static void main(String[] args )
throws IOException, DocumentException, GeneralSecurityException {
String pkcs11Config = "name=eToken\nlibrary=C://WINDOWS//system32//eTPKCS11.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 = "123456";
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();
String alias=null;
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println(alias);
}}
但是我得到一个错误
`Error(2,28): cannot access class sun.security.pkcs11.SunPKCS11; class file has wrong version 49.0, should be 45.3 or 46.0 or 47.0 or 48.0`
请告诉我解决方法。如何下载 49 以下版本的 class,如 48 等
SunPKCS11 在 Java 1.5
中引入
您必须升级 Java 版本,否则仍然无法使用它。
提升项目并不少见。 "The project is already running" 不是避免这种情况的理由,因为这是持续开发过程的预期部分。
我使用此代码在 java1.4 中创建了 keyStore。
`public static void main(String[] args )
throws IOException, DocumentException, GeneralSecurityException {
String pkcs11Config = "name=eToken\nlibrary=C://WINDOWS//system32//eTPKCS11.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 = "123456";
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();
String alias=null;
while (aliases.hasMoreElements()) {
alias = aliases.nextElement();
System.out.println(alias);
}}
但是我得到一个错误
`Error(2,28): cannot access class sun.security.pkcs11.SunPKCS11; class file has wrong version 49.0, should be 45.3 or 46.0 or 47.0 or 48.0`
请告诉我解决方法。如何下载 49 以下版本的 class,如 48 等
SunPKCS11 在 Java 1.5
中引入您必须升级 Java 版本,否则仍然无法使用它。
提升项目并不少见。 "The project is already running" 不是避免这种情况的理由,因为这是持续开发过程的预期部分。