我有一个签署文档的小程序,并将文档、签名和证书发送到服务器端。在服务器端 portlet 接收这 3 个文件,所有文件都以 base64 格式存储,但是当我尝试获取证书时会引发异常
java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:104)
小程序端代码:
public static byte[] certificate;
public static String getCertificateString() {
String str = "";
byte[] result = null;
result = Base64.encode(certificate);
for (int i = 0; i < result.length; i++) {
str += (char) (result[i]);
}
return str;
}
//initialization of certificate from the store
Certificate cert = store.getCertificate(aliasKey);
certificate = cert.toString().getBytes();
在此之后,我将证书发送到需要验证签名的 portlet。但是证书转换失败。
门户代码:
String certificate = request.getParameter("cert");
byte[] cert_array = Base64.decode(certificate.getBytes());
try {
cert = CertificateFactory.getInstance("X509").generateCertificate(new ByteArrayInputStream(cert_array));
}catch(Exception e){
e.printStackTrace();
}
而此时,在 try 块中,引发了 Exception