我正在使用bouncy-castle库制作一个TLS-Handshake并Web-Server获取公共证书。下面是我的代码 private org.bouncycastle.asn1.x509.Certificate[] certificateList; public static void main(String... args) { new BCMain().testBCTLS(); } private void testBCTLS() { try { Socket s = new Socket(InetAddress.getByName(WEB_SERVER), WEB_SERVER_PORT); //TlsProtocolHandler tlsHandler = new TlsProtocolHandler(s.getInputStream(), s.getOutputStream()); TlsClientProtocol protocol = new TlsClientProtocol(s.getInputStream(), s.getOutputStream(), new SecureRandom()); TlsClient client = new DefaultTlsClient() { private Boolean connectionStatus = Boolean.FALSE; @Override public TlsAuthentication getAuthentication() throws IOException { return new ServerOnlyTlsAuthentication() { public void notifyServerCertificate(Certificate serverCertificate) throws IOException { certificateList = serverCertificate.getCertificateList(); } };Subject Alternative Names我想从那个公共证书中提取JDK 的X509Certificate有提取方法..但我想从证书中获取相同的方法。SubjectAlternativeNamesbouncy-castle有人可以帮忙吗?
1 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
我能够从库中提取Subject-Alternative-Names使用X509CertificateHolder和JcaX509CertificateConverter类BouncyCastle..继续上面的代码
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
if (this.certificateList!=null) {
org.bouncycastle.asn1.x509.Certificate certificate = certificateList[0];
X509CertificateHolder holder = new X509CertificateHolder(certificate.getEncoded());
X509Certificate x509Certificate = new JcaX509CertificateConverter().getCertificate(holder);
Collection<List<?>> sanCollections = x509Certificate.getSubjectAlternativeNames();
}
添加回答
举报
0/150
提交
取消