@Test public void testConvertBinarySidToString() throws Exception { byte[] sid = {(byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x15, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xe9, (byte) 0x67, (byte) 0xbb, (byte) 0x98, (byte) 0xd6, (byte) 0xb7, (byte) 0xd7, (byte) 0xbf, (byte) 0x82, (byte) 0x05, (byte) 0x1e, (byte) 0x6c, (byte) 0x28, (byte) 0x06, (byte) 0x00, (byte) 0x00}; String result = LdapUtils.convertBinarySidToString(sid); assertThat(result).isEqualTo("S-1-5-21-2562418665-3218585558-1813906818-1576"); }
public static String convertBinarySidToString(byte[] sid) { StringBuffer sidAsString = new StringBuffer("S-"); sidAsString.append(sid[0]).append('-'); StringBuffer sb = new StringBuffer(); for (int t = 2; t <= 7; t++) { String hexString = Integer.toHexString(sid[t] & 0xFF); sb.append(hexString); } sidAsString.append(Long.parseLong(sb.toString(), HEX)); int count = sid[1]; for (int i = 0; i < count; i++) { int currSubAuthOffset = i * 4; sb.setLength(0); sb.append(toHexString((byte) (sid[11 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[10 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[9 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[8 + currSubAuthOffset] & 0xFF))); sidAsString.append('-').append(Long.parseLong(sb.toString(), HEX)); } return sidAsString.toString(); }
LdapUtils { public static String convertBinarySidToString(byte[] sid) { StringBuffer sidAsString = new StringBuffer("S-"); sidAsString.append(sid[0]).append('-'); StringBuffer sb = new StringBuffer(); for (int t = 2; t <= 7; t++) { String hexString = Integer.toHexString(sid[t] & 0xFF); sb.append(hexString); } sidAsString.append(Long.parseLong(sb.toString(), HEX)); int count = sid[1]; for (int i = 0; i < count; i++) { int currSubAuthOffset = i * 4; sb.setLength(0); sb.append(toHexString((byte) (sid[11 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[10 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[9 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[8 + currSubAuthOffset] & 0xFF))); sidAsString.append('-').append(Long.parseLong(sb.toString(), HEX)); } return sidAsString.toString(); } }
LdapUtils { public static String convertBinarySidToString(byte[] sid) { StringBuffer sidAsString = new StringBuffer("S-"); sidAsString.append(sid[0]).append('-'); StringBuffer sb = new StringBuffer(); for (int t = 2; t <= 7; t++) { String hexString = Integer.toHexString(sid[t] & 0xFF); sb.append(hexString); } sidAsString.append(Long.parseLong(sb.toString(), HEX)); int count = sid[1]; for (int i = 0; i < count; i++) { int currSubAuthOffset = i * 4; sb.setLength(0); sb.append(toHexString((byte) (sid[11 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[10 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[9 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[8 + currSubAuthOffset] & 0xFF))); sidAsString.append('-').append(Long.parseLong(sb.toString(), HEX)); } return sidAsString.toString(); } private  LdapUtils(); }
LdapUtils { public static String convertBinarySidToString(byte[] sid) { StringBuffer sidAsString = new StringBuffer("S-"); sidAsString.append(sid[0]).append('-'); StringBuffer sb = new StringBuffer(); for (int t = 2; t <= 7; t++) { String hexString = Integer.toHexString(sid[t] & 0xFF); sb.append(hexString); } sidAsString.append(Long.parseLong(sb.toString(), HEX)); int count = sid[1]; for (int i = 0; i < count; i++) { int currSubAuthOffset = i * 4; sb.setLength(0); sb.append(toHexString((byte) (sid[11 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[10 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[9 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[8 + currSubAuthOffset] & 0xFF))); sidAsString.append('-').append(Long.parseLong(sb.toString(), HEX)); } return sidAsString.toString(); } private  LdapUtils(); static void closeContext(DirContext context); static NamingException convertLdapException(javax.naming.NamingException ex); static Class getActualTargetClass(DirContext context); static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection); static void collectAttributeValues(
            Attributes attributes, String name, Collection<T> collection, Class<T> clazz); static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler); static String convertCompositeNameToString(
			CompositeName compositeName); static LdapName newLdapName(Name name); static LdapName newLdapName(String distinguishedName); static LdapName removeFirst(Name dn, Name pathToRemove); static LdapName prepend(Name dn, Name pathToPrepend); static LdapName emptyLdapName(); static Rdn getRdn(Name name, String key); static Object getValue(Name name, String key); static Object getValue(Name name, int index); static String getStringValue(Name name, int index); static String getStringValue(Name name, String key); static String convertBinarySidToString(byte[] sid); static byte[] convertStringSidToBinary(String string); }
LdapUtils { public static String convertBinarySidToString(byte[] sid) { StringBuffer sidAsString = new StringBuffer("S-"); sidAsString.append(sid[0]).append('-'); StringBuffer sb = new StringBuffer(); for (int t = 2; t <= 7; t++) { String hexString = Integer.toHexString(sid[t] & 0xFF); sb.append(hexString); } sidAsString.append(Long.parseLong(sb.toString(), HEX)); int count = sid[1]; for (int i = 0; i < count; i++) { int currSubAuthOffset = i * 4; sb.setLength(0); sb.append(toHexString((byte) (sid[11 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[10 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[9 + currSubAuthOffset] & 0xFF))); sb.append(toHexString((byte) (sid[8 + currSubAuthOffset] & 0xFF))); sidAsString.append('-').append(Long.parseLong(sb.toString(), HEX)); } return sidAsString.toString(); } private  LdapUtils(); static void closeContext(DirContext context); static NamingException convertLdapException(javax.naming.NamingException ex); static Class getActualTargetClass(DirContext context); static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection); static void collectAttributeValues(
            Attributes attributes, String name, Collection<T> collection, Class<T> clazz); static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler); static String convertCompositeNameToString(
			CompositeName compositeName); static LdapName newLdapName(Name name); static LdapName newLdapName(String distinguishedName); static LdapName removeFirst(Name dn, Name pathToRemove); static LdapName prepend(Name dn, Name pathToPrepend); static LdapName emptyLdapName(); static Rdn getRdn(Name name, String key); static Object getValue(Name name, String key); static Object getValue(Name name, int index); static String getStringValue(Name name, int index); static String getStringValue(Name name, String key); static String convertBinarySidToString(byte[] sid); static byte[] convertStringSidToBinary(String string);  }