2

尝试创建新证书时出现以下异常:

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)
    {

    }

抛出异常: Collection certificateCollection = cf.generateCertificates(certificateStream);

有人可以帮我理解和解决这个问题吗?

谢谢

4

2 回答 2

1

这是一个基于您的代码的运行良好的示例。它使用一个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);
    }
}
于 2012-08-14T20:55:32.080 回答
0

好吧,我的错。

我从文件中读取证书,并没有将其读取为二进制文件......

读取为二进制解决了这个问题。

非常感谢您的所有回答/评论!

于 2012-08-14T22:50:55.940 回答