尝试创建新证书时,我收到以下异常:
java.security.cert.CertificateParsingException:signed overrun,bytes = 224
try
{
InputStream certificateStream = new ByteArrayInputStream(certificate);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Collection certificateCollection = cf.generateCertificates(certificateStream);
}
catch (CertificateException ex)
{
}
抛出异常: 集合certificateCollection = cf.generateCertificates(certificateStream);
有人可以帮助我理解并解决这个问题吗?
由于
答案 0 :(得分:0)
这是well-functioning example based on your code。它使用FileInputStream
。如果您使用ByteArray,请注意其中的数据:
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.cert.CertificateException;
import java.io.FileNotFoundException;
public class StackOverflow {
public static void main(String[] args) throws FileNotFoundException, CertificateException {
InputStream certificateStream = new FileInputStream("stackoverflow.cert");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Collection certificateCollection = cf.generateCertificates(certificateStream);
}
}
答案 1 :(得分:0)
好的,我的错误。
我从文件中读取证书,但我没有将其视为二进制文件...
二元阅读解决了这个问题。
非常感谢您的所有答案/评论!