我正在我的Android应用程序中执行HTTP基本身份验证。但是,由于服务器上进行了以下更改,最近我在验证用户身份时遇到了问题:

“ ...密钥长度为1,024位或更短的SSL证书将在2010年12月31日之后不足以保证安全。根据这些准则,大多数SSL证书供应商(包括GeoTrust)已开始发行这些新的2048位密钥。 ”

提出了更新我的Java Runtime Environment的建议。但是,从我的应用程序在Android上的状态来看,我认为这不会做任何事情。因此,我的问题是这样的:

如何更改以下代码以使用2048位加密?这可能吗?有人有什么建议吗?我将不胜感激。谢谢!

DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter("Content-type",
        "application/xml");
client.getCredentialsProvider().setCredentials(
        new AuthScope(Constants.SERVER_HOST,
                Constants.SERVER_PORT,
                Constants.SERVER_REALM),
        new UsernamePasswordCredentials(username.getText()
                .toString(), password.getText().toString()));

String getURL = Constants.SERVER_URL;
HttpGet get = new HttpGet(getURL);
responseGet = client.execute(get);


堆栈跟踪错误:

javax.net.ssl.SSLException: Not trusted server certificate
Caused by: java.security.cert.CertificateException:
Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not     found.java.security.cert.CertPathValidatorException:

最佳答案

你不知道该代码与加密无关。服务器的管理员负责将其更新为使用更长的密钥(2048位)。您只需要测试更新后您的应用程序仍然可以工作(似乎没有)。到底是什么问题?无法连接了吗?您遇到什么错误(堆栈跟踪)?

07-24 09:37
查看更多