DistinguishedName { public X500Principal toX500Principal() { return new X500Principal(toString()); } DistinguishedName(String commonName, String localityName, String stateOrProvinceName, String organizationName, String organizationalUnitName, String country, String streetAddress, String domain, String userid); @Override String toString(); X500Principal toX500Principal(); static X500Name toX500Name(@NonNull final X500Principal principal);  }
@Test public void test_toX500Principal() { final DistinguishedName dn = DistinguishedName.builder() .commonName("Alfio Zappala") .country("US") .domain("www.runrightfast.co") .localityName("Rochester") .organizationName("RunRightFast.co") .organizationalUnitName("Executive") .stateOrProvinceName("NY") .streetAddress("123 Main St.") .userid("0123456789") .build(); log.info(String.format("dn =\n%s", dn)); final X500Principal principal = dn.toX500Principal(); log.info(String.format("principle name =\n%s", principal.getName())); final X500Principal principal2 = new X500Principal(principal.getEncoded()); log.info(String.format("principle2 name =\n%s", principal2.getName())); log.info(String.format("principle2 name RFC2253 =\n%s", principal2.getName(X500Principal.RFC2253))); assertThat(Arrays.areEqual(principal.getEncoded(), principal2.getEncoded()), is(true)); assertThat(principal, is(principal2)); }