X500Principal杰出名称顺序

编程入门 行业动态 更新时间:2024-10-25 08:22:01
本文介绍了X500Principal杰出名称顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Bouncycastle lib使用X509v3CertificateBuilder类从PKCS10请求生成证书。

I'm using the Bouncycastle lib to generate certificates from PKCS10 requests using the X509v3CertificateBuilder class.

它返回构建包含生成的证书的X509CertificateHolder对象。 如果我在持有者上调用getIssuer,它会以正确的顺序返回发行者专有名称(如果我在发行者证书上调用getSubjectX500Principal(),则返回相同的名称),如果我使用java从持有者解析编码版本CertificateFactory,生成的证书的getIssuerX500Principal()方法以相反的顺序返回DN,出了什么问题?

It returns build a X509CertificateHolder object which contains the generated certificate. If I call getIssuer on the holder, it returns the issuer distinguished name in the correct order (the same returned if I call getSubjectX500Principal() on the issuer certificate), if I parse the encoded version from the holder using the java CertificateFactory, the getIssuerX500Principal() method of the generated certificate returns the DN in the opposite order, what's wrong?

以下是我正在尝试做的示例代码:

Here is an example code of what I'm trying to do:

X509CertificateHolder holder = certBuilder.build(sigGen); holder.getIssuer(); //Returns the DN in the correct order (same as in issuer cert) CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(holder.getEncoded())); cert.getIssuerX500Principal().getName(); //Returns issuer DN in reverse order

推荐答案

因为我需要为了比较专有名称,我通过使用LdapName类解析DN并比较解析的rdns来解决:

Since I need to compare distinguished names, I resolved by parsing the DN with LdapName class and comparing the parsed rdns:

boolean DNmatches(X500Principal p1, X500Principal p2) { List<Rdn> rdn1 = new LdapName(p1.getName()).getRdns(); List<Rdn> rdn2 = new LdapName(p2.getName()).getRdns(); if(rdn1.size() != rdn2.size()) return false; return rdn1.containsAll(rdn2); }

更多推荐

X500Principal杰出名称顺序

本文发布于:2023-11-16 21:13:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:杰出   顺序   名称   X500Principal

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!