本文整理汇总了Java中org.spongycastle.asn1.x500.X500Name.getRDNs方法的典型用法代码示例。如果您正苦于以下问题:Java X500Name.getRDNs方法的具体用法?Java X500Name.getRDNs怎么用?Java X500Name.getRDNs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongycastle.asn1.x500.X500Name
的用法示例。
在下文中一共展示了X500Name.getRDNs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueByObjectIdentifier
import org.spongycastle.asn1.x500.X500Name; //导入方法依赖的package包/类
public String getValueByObjectIdentifier(ASN1ObjectIdentifier identifier) {
X500Name x500name = null;
try {
x500name = new JcaX509CertificateHolder(certificate).getSubject();
} catch (CertificateEncodingException e) {
Timber.e(e, "Error getting value by ASN1 Object identifier");
}
if (x500name == null) {
return null;
}
RDN[] rdNs = x500name.getRDNs(identifier);
if (rdNs.length == 0) {
return null;
}
RDN c = rdNs[0];
return IETFUtils.valueToString(c.getFirst().getValue());
}
示例2: getDisplayNameFromCertificate
import org.spongycastle.asn1.x500.X500Name; //导入方法依赖的package包/类
/**
* Returns either a string that "sums up" the certificate for humans, in a similar manner to what you might see
* in a web browser, or null if one cannot be extracted. This will typically be the common name (CN) field, but
* can also be the org (O) field, org+location+country if withLocation is set, or the email
* address for S/MIME certificates.
*/
@Nullable
public static String getDisplayNameFromCertificate(@Nonnull X509Certificate certificate, boolean withLocation) throws CertificateParsingException {
X500Name name = new X500Name(certificate.getSubjectX500Principal().getName());
String commonName = null, org = null, location = null, country = null;
for (RDN rdn : name.getRDNs()) {
AttributeTypeAndValue pair = rdn.getFirst();
String val = ((ASN1String) pair.getValue()).getString();
ASN1ObjectIdentifier type = pair.getType();
if (type.equals(RFC4519Style.cn))
commonName = val;
else if (type.equals(RFC4519Style.o))
org = val;
else if (type.equals(RFC4519Style.l))
location = val;
else if (type.equals(RFC4519Style.c))
country = val;
}
final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
String altName = null;
if (subjectAlternativeNames != null)
for (final List<?> subjectAlternativeName : subjectAlternativeNames)
if ((Integer) subjectAlternativeName.get(0) == 1) // rfc822name
altName = (String) subjectAlternativeName.get(1);
if (org != null) {
return withLocation ? Joiner.on(", ").skipNulls().join(org, location, country) : org;
} else if (commonName != null) {
return commonName;
} else {
return altName;
}
}
示例3: getDisplayNameFromCertificate
import org.spongycastle.asn1.x500.X500Name; //导入方法依赖的package包/类
/**
* Returns either a string that "sums up" the certificate for humans, in a similar manner to what you might see
* in a web browser, or null if one cannot be extracted. This will typically be the common name (CN) field, but
* can also be the org (O) field, org+location+country if withLocation is set, or the email
* address for S/MIME certificates.
*/
public static @Nullable String getDisplayNameFromCertificate(@Nonnull X509Certificate certificate, boolean withLocation) throws CertificateParsingException {
X500Name name = new X500Name(certificate.getSubjectX500Principal().getName());
String commonName = null, org = null, location = null, country = null;
for (RDN rdn : name.getRDNs()) {
AttributeTypeAndValue pair = rdn.getFirst();
String val = ((ASN1String) pair.getValue()).getString();
ASN1ObjectIdentifier type = pair.getType();
if (type.equals(RFC4519Style.cn))
commonName = val;
else if (type.equals(RFC4519Style.o))
org = val;
else if (type.equals(RFC4519Style.l))
location = val;
else if (type.equals(RFC4519Style.c))
country = val;
}
final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
String altName = null;
if (subjectAlternativeNames != null)
for (final List<?> subjectAlternativeName : subjectAlternativeNames)
if ((Integer) subjectAlternativeName.get(0) == 1) // rfc822name
altName = (String) subjectAlternativeName.get(1);
if (org != null) {
return withLocation ? Joiner.on(", ").skipNulls().join(org, location, country) : org;
} else if (commonName != null) {
return commonName;
} else {
return altName;
}
}
示例4: commonNameFromX500Name
import org.spongycastle.asn1.x500.X500Name; //导入方法依赖的package包/类
private static String commonNameFromX500Name(X500Name name) {
String commonName = "";
RDN[] rdns = name.getRDNs(BCStyle.CN);
if (rdns == null || rdns.length == 0)
return commonName;
commonName = IETFUtils.valueToString(rdns[0].getFirst().getValue());
return commonName;
}
示例5: getCommonName
import org.spongycastle.asn1.x500.X500Name; //导入方法依赖的package包/类
/**
* @param certificate certificate
* @return common name
* @throws IllegalArgumentException if certificate is incorrect type
*/
@NonNull
public static String getCommonName(Certificate certificate) {
assertX509Certificate(certificate);
String result = null;
try {
X500Name x500name = new JcaX509CertificateHolder((X509Certificate) certificate).getSubject();
RDN cn = x500name.getRDNs(BCStyle.CN)[0];
result = IETFUtils.valueToString(cn.getFirst().getValue());
} catch (CertificateEncodingException ignored) {
}
return (result == null) ? "" : result;
}