使用 Bouncy-Castle 库从证书中读取 SubjectAlternativeNames

我正在使用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


有人可以帮忙吗?


神不在的星期二
浏览 158回答 1
1回答

月关宝盒

我能够从库中提取Subject-Alternative-Names使用X509CertificateHolder和JcaX509CertificateConverter类BouncyCastle..继续上面的代码import org.bouncycastle.cert.X509CertificateHolder;import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;if (this.certificateList!=null) {&nbsp; &nbsp; &nbsp;org.bouncycastle.asn1.x509.Certificate certificate = certificateList[0];&nbsp; &nbsp; &nbsp;X509CertificateHolder holder = new X509CertificateHolder(certificate.getEncoded());&nbsp; &nbsp; &nbsp;X509Certificate x509Certificate = new JcaX509CertificateConverter().getCertificate(holder);&nbsp; &nbsp; &nbsp;Collection<List<?>> sanCollections = x509Certificate.getSubjectAlternativeNames();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java