1

我正在尝试打开一个受密码保护的密钥库文件,该文件位于 jre 安全目录中。我使用 Bouncy Castel 作为我的 JCE。出于某种原因,我似乎遇到了一些我不知道原因的例外情况。请帮忙。谢谢。这是我所拥有的:

代码片段:

        String passwd = "abcd123";
        try {
            String file = "C:\\Program Files\\Java\\jre7\\lib\\security\\keystore.ssm";
            System.out.println("file =" + file);
            File keystoreFile = new File(file);
            if (keystoreFile.exists()) {
                KeyStore store = KeyStore.getInstance("PKCS12", "BC"); 
                //KeyStore store = KeyStore.getInstance("PKCS12");
                FileInputStream in = new FileInputStream(keystoreFile);
                store.load(in, passwd.toCharArray());
                // Key key = store.getKey("mykeystore",passwd.toCharArray());
            }

        } catch (KeyStoreException ex) {
            Logger.getLogger(SimpleBCTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchProviderException ex) {
         Logger.getLogger(SimpleBCTest.class.getName()).log(Level.SEVERE, null, ex);
         }  catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(SimpleBCTest.class.getName()).log(Level.SEVERE, null, ex);
        } /*catch (UnrecoverableKeyException ex) {
         Logger.getLogger(SimpleBCTest.class.getName()).log(Level.SEVERE, null, ex);
         } */ catch (IOException ex) {
            Logger.getLogger(SimpleBCTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CertificateException ex) {
            Logger.getLogger(SimpleBCTest.class.getName()).log(Level.SEVERE, null, ex);
        }

我得到的例外:

线程“主”java.lang.ClassCastException 中的异常:org.bouncycastle.asn1.DLSequence 无法转换为 org.bouncycastle.asn1.ASN1Integer

4

0 回答 0