关于java通过ssl连接mqtt

我这边java在没有通过ssl连接mqtt的时候是可以连接的(可以订阅与发布),
但是通过ssl就不行了,发现是读取证书的时候出错了,错误是这样的:

java.security.cert.CertificateException: Unable to initialize, java.io.IOException: extra data given to DerValue constructor

at sun.security.x509.X509CertImpl.(Unknown Source)
at sun.security.provider.X509Factory.engineGenerateCertificate(Unknown Source)
at java.security.cert.CertificateFactory.generateCertificate(Unknown Source)
at com.test.mqtt.AppTest.main(AppTest.java:51)

Caused by: java.io.IOException: extra data given to DerValue constructor

at sun.security.util.DerValue.init(Unknown Source)
at sun.security.util.DerValue.(Unknown Source)
at sun.security.util.DerValue.(Unknown Source)
... 4 more

具体代码是:
CertificateFactory cf;

try {
    cf = CertificateFactory.getInstance("X.509");
     FileInputStream crtIn = new FileInputStream("D:\\test\\client.crt");
     X509Certificate caCert = (X509Certificate) cf.generateCertificate(crtIn);
        //Certificate caCert =  cf.generateCertificate(crtIn);
        crtIn.close();
} catch (CertificateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问