当我在套接字连接中收到 SSL 握手上的 X509Certificate 链时,我必须将 X509Certificate 链导出到 base64 编码的 .cer 文件。
我尝试使用以下代码。但文件内容与原证书不一样。
private static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
private static final String END_CERT = "-----END CERTIFICATE-----";
X509Certificate[] x509Certificates;
--------------
--------------
String certContent="";
for(int i=0;i<x509Certificates.length;i++)
{
certContent += Base64.encode(x509Certificates[i].getEncoded());
}
BufferedWriter writer = new BufferedWriter(new FileWriter("mycert.cer"));
writer.write(BEGIN_CERT);
writer.newLine();
writer.write(certContent);
writer.newLine();
writer.write(END_CERT);
writer.close();
上述代码中有任何建议/更正吗?