亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 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 關注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號