为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

神不在的星期二 2023-05-17 14:31:53
我正在使用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();

}


查看完整回答
反对 回复 2023-05-17
  • 1 回答
  • 0 关注
  • 157 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信