当前位置: 首页 > 知识库问答 >
问题:

Bouncy Castle密钥存储(BKS):java.io.IOException:密钥存储的版本错误

邹玮
2023-03-14

我必须连接到一个基于REST的WebService。

(https://someurl.com/api/lookup/jobfunction/lang/en)

在IE或chrome浏览器中,当我尝试访问这个URL时,我会得到一个证书,我必须信任它并接受它才能继续,然后我必须输入用户名和密码,然后我会得到JSON响应。

同样的事情,我必须为一个android应用程序编程。

>

  • 尝试使用自定义EasySSLSocketFactory和EasyX509TrustManager,但无效。我得到以下错误:java.security.cert.CertPathValidateXception:找不到认证路径的信任锚。

    使用了BKS密钥库,请注意在我执行以下命令之前mykeystore.BKS是一个空文件

    keytool -importcert -v -trustcacerts -file "test.crt" -alias IntermediateCA -keystore   "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath   "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234
    
    
    keytool -list -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider  -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234
    

    myHttpClient.java如下所示:

    public class MyHttpClient extends DefaultHttpClient { 
    
    final Context context; 
    
    public MyHttpClient(Context context) { 
        this.context = context; 
    } 
    
    @Override
    protected ClientConnectionManager createClientConnectionManager() { 
        SchemeRegistry registry = new SchemeRegistry(); 
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
        // Register for port 443 our SSLSocketFactory with our keystore 
        // to the ConnectionManager 
        registry.register(new Scheme("https", newSslSocketFactory(), 443)); 
        return new SingleClientConnManager(getParams(), registry); 
    } 
    
    private SSLSocketFactory newSslSocketFactory() { 
        try { 
            // Get an instance of the Bouncy Castle KeyStore format 
            KeyStore trusted = KeyStore.getInstance("BKS"); 
            // Get the raw resource, which contains the keystore with 
            // your trusted certificates (root and any intermediate certs) 
            InputStream in = context.getResources().openRawResource(R.raw.mykeystore); 
            try { 
                // Initialize the keystore with the provided trusted certificates 
                // Also provide the password of the keystore 
                trusted.load(in, "abcd1234".toCharArray()); 
            } finally { 
                in.close(); 
            } 
            // Pass the keystore to the SSLSocketFactory. The factory is responsible 
            // for the verification of the server certificate. 
            SSLSocketFactory sf = new SSLSocketFactory(trusted); 
            // Hostname verification from certificate 
            // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 
            sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); 
            return sf; 
        } catch (Exception e) { 
            throw new AssertionError(e); 
        } 
    } 
    

    当我调用html" target="_blank">webservice时,我会得到以下错误:java.lang.AssertionError:java.io.ioException:密钥存储的错误版本

    请告诉我需要做什么才能连接到基于HTTPS的rest webservice,它具有用户名和密码凭据。......

  • 共有1个答案

    那弘
    2023-03-14

    我得到了别人的帮助。解决方法如下:

    • 1,下载工具密钥库资源管理器
    • 2,安装后,打开您的bks证书,然后找到工具->更改类型
    • 3,选择BKS-V1,然后保存并使用。
     类似资料:
    • 11:12:17,289信息[org.apache.Coyote.http11.http11protocol](MSC服务线程1-2)JBWeb003001:Coyote http/1.1正在初始化:http-/0.0.0.0:8080 11:12:17,297信息[org.apache.Coyote.http11.http11protocol](MSC服务线程1-2)JBWeb003000:Co

    • 当我尝试使用较低版本的android登录我的应用程序时,会发生此错误。所有安装了android 4.3及以上版本的手机/模拟器都能够无误登录,其中4.1.1版的手机和平板电脑会出现以下错误。我们认为这是因为android版本较低,正在寻找任何解决方案。 我目前试图降低我的版本的充气城堡到146像在这个链接 “密钥存储版本错误”错误。如何创建版本=1的密钥库证书? 我已经被困在这个问题上一天了,所以

    • 我正在使用ionic开发一个android应用程序。我用一个新的密钥库错误地给我的应用程序签名。当我将应用程序上传到PlayStore时发现证书不相等时,我使用了与PlayStore中所需证书相同的备份keystore文件。 现在,如果我想用命令对我的。apk进行jarsign 我得到以下错误 我谷歌了很多,但我不确定是否有任何解决方案可以帮助我。我必须使用我的旧证书,不能使用一个新的,因为我不能

    • 我在使用SSL时遇到了困难,因为我得到了以下与我的密钥存储相关的错误(使用keytool per:http://developer.android.com/tools/publishing/app-signing.html自创建和自签名): 08-14 20:55:23.044:W/System.err(5430):java.io.ioException:密钥存储的版本错误。08-14 20:55

    • 使用/生成的密钥和证书存储在称为密钥库的数据库中。 默认情况下,此数据库存储在名为.keystore的文件中。 您可以使用java.security包的KeyStore类访问此数据库的内容。 它管理三个不同的条目,即PrivateKeyEntry,SecretKeyEntry,TrustedCertificateEntry。 PrivateKeyEntry SecretKeyEntry Trust

    • 对于PGP想要使用的签名和加密密钥,我是否可以使用2个JCE、RSA或DSA keypairs?把它们保存在密钥库中,当我想使用这些密钥时,只需按需重建PGP基础结构?