How can I convert a string to OctetString (C #)?

I am importing data into an LDAP store. This attribute is of type OctetString. I have a normal line where I need to hit this attribute.

I am using C # (.net 3.5)

How can I do it?

+1


a source to share


3 answers


As far as I know, OctetString is just an array of bytes. Not to be confused with Octal (base 8)

Fully open to correction, but some random searches seem to agree ... This will convert your string to a byte array



byte[] octets = System.Text.Encoding.ASCII.GetBytes("abcd"); 

      

+1


a source


System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
byte[] octets = utf8.GetBytes("Réne");

      



+1


a source


An OctetString

appears to be just a string, represented as an array of bytes (hence octets).

The MSDN page on Octet String Property Type (SID) provides the following example for writing an Octet string:

byte[] usrSID = (byte[])usr.Properties["objectSid"].Value;
usr.Properties["objectSid "].Clear();
usr.Properties["objectSid "].Value = usrSID;
usr.CommitChanges();

      

0


a source







All Articles