locked
byte to SID string for 2003 active directory RRS feed

  • Question

  • User181721010 posted

    Hi,
    We are trying to convert the byte format SID to a string. For that we use the following code(got it from one of MSDN blogs). However this code does not seem to be working for 2003 AD. The string SID that we get from this is not the right one. We need some urgent help in this regard. Will appreciate any help.

    The code below is in java....(I know this may not be the right place). But if someone can point us to some resource which talks about how to decode the byte stream it will be really helpful.

     

    public static final String binarySidToStringSid(byte[] SID) {

    String strSID = "";

    // convert the SID into string format

    long version;
    long authority;
    long count;
    long rid;

    strSID = "S";
    version = SID[0];
    strSID = strSID + "-" + Long.toString(version);
    authority = SID[4];

    for (int i = 0; i < 4; i++) {
    authority <<= 8;
    authority += SID[4 + i] & 0xFF;
    }

    strSID = strSID + "-" + Long.toString(authority);
    count = SID[2];
    count <<= 8;
    count += SID[1] & 0xFF;

    for (int j = 0; j < count; j++) {

    rid = SID[11 + (j * 4)] & 0xFF;

    for (int k = 1; k < 4; k++) {

    rid <<= 8;

    rid += SID[11 - k + (j * 4)] & 0xFF;

    }

    strSID = strSID + "-" + Long.toString(rid);

    }

    return strSID;

    }


    Regards
    Sourashis

    Sunday, December 21, 2008 2:42 PM

All replies

  • User1695803477 posted

    SecurityIdentifier class can do this for you: new SecurityIdentifier( SID, 0 )

    Sunday, January 11, 2009 8:24 AM