// Get the current user's SID WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent(); SecurityIdentifier currentSid = currentIdentity.User; // Convert the current user's SID to its binary form byte[] sidBinaryForm = currentSid.GetBinaryForm(); // Display the binary representation of the SID foreach (byte b in sidBinaryForm) { Console.Write("{0:X2} ", b); }
// Get a SID from a string string sidString = "S-1-5-21-3623811015-3361044348-30300820-1013"; SecurityIdentifier sid = new SecurityIdentifier(sidString); // Convert the SID to its binary form byte[] sidBinaryForm = sid.GetBinaryForm(); // Display the binary representation of the SID foreach (byte b in sidBinaryForm) { Console.Write("{0:X2} ", b); }Package library: System.Security.Principal.