本文整理汇总了Java中org.bouncycastle.asn1.x500.AttributeTypeAndValue类的典型用法代码示例。如果您正苦于以下问题:Java AttributeTypeAndValue类的具体用法?Java AttributeTypeAndValue怎么用?Java AttributeTypeAndValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeTypeAndValue类属于org.bouncycastle.asn1.x500包,在下文中一共展示了AttributeTypeAndValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendTypeAndValue
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public static void appendTypeAndValue(
StringBuffer buf,
AttributeTypeAndValue typeAndValue,
Hashtable oidSymbols)
{
String sym = (String)oidSymbols.get(typeAndValue.getType());
if (sym != null)
{
buf.append(sym);
}
else
{
buf.append(typeAndValue.getType().getId());
}
buf.append('=');
buf.append(valueToString(typeAndValue.getValue()));
}
示例2: getCommonName
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public static String getCommonName(X500Name name) {
ParamUtil.requireNonNull("name", name);
RDN[] rdns = name.getRDNs(ObjectIdentifiers.DN_CN);
if (rdns != null && rdns.length > 0) {
RDN rdn = rdns[0];
AttributeTypeAndValue atv = null;
if (rdn.isMultiValued()) {
for (AttributeTypeAndValue m : rdn.getTypesAndValues()) {
if (m.getType().equals(ObjectIdentifiers.DN_CN)) {
atv = m;
break;
}
}
} else {
atv = rdn.getFirst();
}
return (atv == null) ? null : rdnValueToString(atv.getValue());
}
return null;
}
示例3: verifyCertificateCommonName
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
static void verifyCertificateCommonName(X500Name subject, String commonName) {
List<AttributeTypeAndValue> attributesAndValues = Arrays.stream(subject.getRDNs())
.flatMap(rdn -> rdn.isMultiValued() ?
Stream.of(rdn.getTypesAndValues()) : Stream.of(rdn.getFirst()))
.filter(attr -> attr.getType() == BCStyle.CN)
.collect(Collectors.toList());
if (attributesAndValues.size() != 1) {
throw new IllegalArgumentException("Only 1 common name should be set");
}
String actualCommonName = DERUTF8String.getInstance(attributesAndValues.get(0).getValue()).getString();
if (! actualCommonName.equals(commonName)) {
throw new IllegalArgumentException("Expected common name to be " + commonName + ", but was " + actualCommonName);
}
}
示例4: RdnPanelList
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public RdnPanelList(X500Name x500Name, boolean editable) {
setLayout(new MigLayout("insets dialog, flowy", "[right]", "[]rel[]"));
// we have to reverse RDN order for dialog
List<RDN> rdnsAsList = Arrays.asList(x500Name.getRDNs());
Collections.reverse(rdnsAsList);
for (RDN rdn : rdnsAsList) {
this.editable = editable;
for (AttributeTypeAndValue atav : rdn.getTypesAndValues()) {
String type = OidDisplayNameMapping.getDisplayNameForOid(atav.getType().getId());
String value = atav.getValue().toString();
addItem(new RdnPanel(new JComboBox<Object>(comboBoxEntries), type, value, this, editable));
}
}
}
示例5: match
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public boolean match(Certificate cert) {
if (!(cert instanceof X509Certificate)) {
return false;
}
if (rdnArray == null) {
return true;
}
try {
X500Name x500name = getX500SubjectName((X509Certificate) cert);
boolean ok = true;
for (RDN rdn : rdnArray) {
AttributeTypeAndValue expectedTypeAndValue = rdn.getFirst();
ok = ok && contains(x500name, expectedTypeAndValue);
}
return ok;
} catch (CertificateEncodingException e) {
return false;
}
}
示例6: checkRdn
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
private boolean checkRdn(RDN certRDN, AttributeTypeAndValue expectedTypeAndValue) {
String expectedValue = IETFUtils.valueToString(expectedTypeAndValue.getValue());
boolean constraintFound = false;
AttributeTypeAndValue[] typesAndValues = certRDN.getTypesAndValues();
for (AttributeTypeAndValue typesAndValue : typesAndValues) {
if (typesAndValue.getType().equals(expectedTypeAndValue.getType())) {
String actualValue = IETFUtils.valueToString(typesAndValue.getValue());
if (actualValue.equals(expectedValue)) {
constraintFound = true;
} else {
constraintFound = false;
break;
}
}
}
return constraintFound;
}
示例7: appendTypeAndValue
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public static void appendTypeAndValue(
StringBuilder buf,
AttributeTypeAndValue typeAndValue,
Map<ASN1ObjectIdentifier, String> oidSymbols)
{
String sym = oidSymbols.get(typeAndValue.getType());
if (sym != null)
{
buf.append(sym);
}
else
{
buf.append(typeAndValue.getType().getId());
}
buf.append('=');
buf.append(valueToString(typeAndValue.getValue()));
}
示例8: appendRDN
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public static void appendRDN(
StringBuffer buf,
RDN rdn,
Hashtable oidSymbols)
{
if (rdn.isMultiValued())
{
AttributeTypeAndValue[] atv = rdn.getTypesAndValues();
boolean firstAtv = true;
for (int j = 0; j != atv.length; j++)
{
if (firstAtv)
{
firstAtv = false;
}
else
{
buf.append('+');
}
IETFUtils.appendTypeAndValue(buf, atv[j], oidSymbols);
}
}
else
{
IETFUtils.appendTypeAndValue(buf, rdn.getFirst(), oidSymbols);
}
}
示例9: atvAreEqual
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
private static boolean atvAreEqual(AttributeTypeAndValue atv1, AttributeTypeAndValue atv2)
{
if (atv1 == atv2)
{
return true;
}
if (atv1 == null)
{
return false;
}
if (atv2 == null)
{
return false;
}
ASN1ObjectIdentifier o1 = atv1.getType();
ASN1ObjectIdentifier o2 = atv2.getType();
if (!o1.equals(o2))
{
return false;
}
String v1 = IETFUtils.canonicalize(IETFUtils.valueToString(atv1.getValue()));
String v2 = IETFUtils.canonicalize(IETFUtils.valueToString(atv2.getValue()));
if (!v1.equals(v2))
{
return false;
}
return true;
}
示例10: calculateHashCode
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public int calculateHashCode(X500Name name)
{
int hashCodeValue = 0;
RDN[] rdns = name.getRDNs();
// this needs to be order independent, like equals
for (int i = 0; i != rdns.length; i++)
{
if (rdns[i].isMultiValued())
{
AttributeTypeAndValue[] atv = rdns[i].getTypesAndValues();
for (int j = 0; j != atv.length; j++)
{
hashCodeValue ^= atv[j].getType().hashCode();
hashCodeValue ^= calcHashCode(atv[j].getValue());
}
}
else
{
hashCodeValue ^= rdns[i].getFirst().getType().hashCode();
hashCodeValue ^= calcHashCode(rdns[i].getFirst().getValue());
}
}
return hashCodeValue;
}
示例11: reorderDn
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
/**
* Reorders DN to the order the elements appear in the RFC 2253 table
*
* https://www.ietf.org/rfc/rfc2253.txt
*
* String X.500 AttributeType
* ------------------------------
* CN commonName
* L localityName
* ST stateOrProvinceName
* O organizationName
* OU organizationalUnitName
* C countryName
* STREET streetAddress
* DC domainComponent
* UID userid
*
* @param dn a possibly unordered DN
* @return the ordered dn
*/
public static String reorderDn(String dn) {
RDN[] rdNs = new X500Name(dn).getRDNs();
Arrays.sort(rdNs, new Comparator<RDN>() {
@Override
public int compare(RDN o1, RDN o2) {
AttributeTypeAndValue o1First = o1.getFirst();
AttributeTypeAndValue o2First = o2.getFirst();
ASN1ObjectIdentifier o1Type = o1First.getType();
ASN1ObjectIdentifier o2Type = o2First.getType();
Integer o1Rank = dnOrderMap.get(o1Type);
Integer o2Rank = dnOrderMap.get(o2Type);
if (o1Rank == null) {
if (o2Rank == null) {
int idComparison = o1Type.getId().compareTo(o2Type.getId());
if (idComparison != 0) {
return idComparison;
}
return String.valueOf(o1Type).compareTo(String.valueOf(o2Type));
}
return 1;
} else if (o2Rank == null) {
return -1;
}
return o1Rank - o2Rank;
}
});
return new X500Name(rdNs).toString();
}
示例12: appendRDN
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
public static void appendRDN(
StringBuffer buf,
RDN rdn,
Hashtable oidSymbols)
{
if (rdn.isMultiValued())
{
AttributeTypeAndValue[] atv = rdn.getTypesAndValues();
boolean firstAtv = true;
for (int j = 0; j != atv.length; j++)
{
if (firstAtv)
{
firstAtv = false;
}
else
{
buf.append('+');
}
IETFUtils.appendTypeAndValue(buf, atv[j], oidSymbols);
}
}
else
{
if (rdn.getFirst() != null)
{
IETFUtils.appendTypeAndValue(buf, rdn.getFirst(), oidSymbols);
}
}
}
示例13: getEmailFromCert
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
/**
* Extract email addresses from a certificate
*
* @param cert the X509 certificate holder
* @return a List of all email addresses found
* @throws CertificateException
*/
private static List<String> getEmailFromCert(X509CertificateHolder cert)
throws CertificateException {
List<String> res = new ArrayList<>();
X500Name subject = cert.getSubject();
for (RDN emails : subject.getRDNs(BCStyle.EmailAddress)) {
for (AttributeTypeAndValue emailAttr: emails.getTypesAndValues()) {
log.debug("Add email from RDN: " + IETFUtils.valueToString(emailAttr.getValue()));
res.add(IETFUtils.valueToString(emailAttr.getValue()));
}
}
Extension subjectAlternativeNames = cert
.getExtension(Extension.subjectAlternativeName);
if (subjectAlternativeNames != null) {
for (GeneralName name : GeneralNames.getInstance(
subjectAlternativeNames.getParsedValue()).getNames()) {
if (name.getTagNo() == GeneralName.rfc822Name) {
String email = IETFUtils.valueToString(name.getName());
log.debug("Add email from subjectAlternativeName: " + email);
res.add(email);
}
}
}
return res;
}
示例14: toString
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
@Override
public String toString(X500Name name) {
// Convert in reverse
StringBuffer buf = new StringBuffer();
boolean first = true;
RDN[] rdns = name.getRDNs();
for (int i = rdns.length - 1; i >= 0; i--) {
if (first) {
first = false;
} else {
buf.append(',');
}
if (rdns[i].isMultiValued()) {
AttributeTypeAndValue[] atv = rdns[i].getTypesAndValues();
boolean firstAtv = true;
for (int j = 0; j != atv.length; j++) {
if (firstAtv) {
firstAtv = false;
} else {
buf.append('+');
}
IETFUtils.appendTypeAndValue(buf, atv[j], DefaultSymbols);
}
} else {
IETFUtils.appendTypeAndValue(buf, rdns[i].getFirst(), DefaultSymbols);
}
}
return buf.toString();
}
示例15: extractCommonName
import org.bouncycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
private static String extractCommonName(X500Name name) {
for (RDN rdn : name.getRDNs()) {
AttributeTypeAndValue atav = rdn.getFirst();
if (atav.getType().equals(BCStyle.CN)) {
return atav.getValue().toString();
}
}
return null;
}