java.security.cert.CertificateParsingException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11959576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.security.cert.CertificateParsingException
提问by Matan
I'm getting the following exception when trying to create a new certificate:
尝试创建新证书时出现以下异常:
java.security.cert.CertificateParsingException: signed overrun, bytes = 224
java.security.cert.CertificateParsingException:签名溢出,字节 = 224
try
{
InputStream certificateStream = new ByteArrayInputStream(certificate);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Collection certificateCollection = cf.generateCertificates(certificateStream);
}
catch (CertificateException ex)
{
}
the exception is thrown in: Collection certificateCollection = cf.generateCertificates(certificateStream);
抛出异常: Collection certificateCollection = cf.generateCertificates(certificateStream);
can someone help me to understand and solve this issue?
有人可以帮助我理解和解决这个问题吗?
Thanks
谢谢
采纳答案by Matan
Ok, my mistake.
好吧,我的错。
I read the certificate from file, and I didn't read it as binary...
我从文件中读取了证书,但我没有将其作为二进制文件读取...
Reading as binary solved this issue.
作为二进制读取解决了这个问题。
Thanks alot for all your answers / comments!
非常感谢您的所有回答/评论!
回答by Jér?me Radix
Here is a well-functioning example based on your code. It uses a FileInputStream
. If you use a ByteArray, be careful of the data within it :
这是一个基于您的代码运行良好的示例。它使用一个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);
}
}