The last post is most relevant. I used it to write a class which stored a binary attribute into a string. I haven't used it for a while; but it worked at the time.
Code:
byte[] SID = (byte[]) attributes.get(OBJECTSID).get();
String strSID = getSIDasStringOfBytes(SID);
returnUserData.setObjectSid(strSID);
Code:
private static String getSIDasStringOfBytes(byte[] sid) {
String strSID = "";
int version;
long authority;
int count;
String rid = "";
strSID = "S";
// get version
version = sid[0];
strSID = strSID + "-" + Integer.toString(version);
for (int i = 6; i > 0; i--) {
rid += byte2hex(sid[i]);
}
// get authority
authority = Long.parseLong(rid);
strSID = strSID + "-" + Long.toString(authority);
// next byte is the count of sub-authorities
count = sid[7] & 0xFF;
// iterate all the sub-auths
for (int i = 0; i < count; i++) {
rid = "";
for (int j = 11; j > 7; j--) {
rid += byte2hex(sid[j + (i * 4)]);
}
strSID = strSID + "-" + Long.parseLong(rid, 16);
}
return strSID;
}
Code:
private static String byte2hex(byte b) {
String ret = Integer.toHexString((int) b & 0xFF);
if (ret.length() < 2)
ret = "0" + ret;
return ret;
}