string accountName = "MYDOMAIN\\myusername"; NTAccount ntAccount = new NTAccount(accountName); SecurityIdentifier sid = (SecurityIdentifier)ntAccount.Translate(typeof(SecurityIdentifier));
string sidString = "S-1-5-21-3623811015-3361044348-30300820-1013"; SecurityIdentifier sid = new SecurityIdentifier(sidString); NTAccount ntAccount = (NTAccount)sid.Translate(typeof(NTAccount));In this example, we create a SecurityIdentifier object from its string representation, and then use the Translate() method to obtain the corresponding NTAccount object. This class belongs to the "System.Security.Principal" package library in C#.