以编程方式从J2ME接受自签名证书

时间:2011-07-18 06:00:47

标签: java-me https self-signed

我已经创建了自签名证书并配置了tomcat来使用它(端口443)

当我尝试通过j2me应用程序访问它时,我得到CertificateException

  public void run() {
    String url = "https://192.168.1.40/test/index.jsf";    
    try {
      HttpsConnection hc = (HttpsConnection)Connector.open(url);      
      int respCode= hc.getResponseCode();
    }catch (IOException ioe) {
      Alert a = new Alert(ioe.toString(), null, AlertType.INFO);
    }

javax.microedition.pki.CertificateException:证书验证失败

我认为模拟器可以选择导入证书但是 有没有办法用j2me jar包装证书,并让它接受真实移动设备中的自签名证书。

1 个答案:

答案 0 :(得分:1)

一个迟到的答案:很少有手机有这样的功能(导入根证书),我不记得确切,可能是SE(sonyericsson)手机和诺基亚Symbian(不是所有型号)。大多数手机都不支持此功能。

您可以考虑在J2ME代码中使用SSL加密,例如bouncycastle,请参阅此处:Client side ssl in J2me?

相关问题