我已经使用X.509
创建了openssl
证书,证书具有我需要能够在Java代码中读取的自定义扩展。我使用以下代码创建了证书:
openssl req -new -x509 -key myCA.key -out mtCA.csr -days 1000 -config openssl.cfg
现在,在Java代码中读取证书中扩展名值的最简单方法是什么?或者更一般的是解析x509
证书的最简单方法是什么?
答案 0 :(得分:0)
使用java.security.cert.CertificateFactory和java.security.cert.X509Certificate
private void read(File file) throws Exception {
InputStream in = new FileInputStream(file);
CertificateFactory factory = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) factory.generateCertificate(in);
// read X509Certificate
}