I have the user's SID as byte[]
within windowsPrincipal.getIdentity().getSid()
.
How can I get an Active Directory entry (DirectoryEntry) from the SID?
Use the SecurityIdentifier class to convert the sid from byte[] format to string and then bind directly to the object:
DirectoryEntry OpenEntry(byte[] sidAsBytes)
{
var sid = new SecurityIdentifier(sidAsBytes, 0);
return new DirectoryEntry(string.Format("LDAP://<SID={0}>", sid.ToString()));
}