Link to home
Start Free TrialLog in
Avatar of Pollin
Pollin

asked on

SID convert to string

Does anybody knows how to convert a SID from byte to the string format   S-1-55-11..... ????

I am using

Dim userEntry As New System.DirectoryServices.DirectoryEntry(user1)
userEntry.Properties("objectSid").Value

to retrieve the SID from AD but it is in byte type. I need to show it in a text box and compare it with another SID.

I tried to use

                Dim enc As New System.Text.ASCIIEncoding
                Response.Write(enc.GetString(userEntry.Properties("objectSid").Value))

but it show unreadable data and I need the format S-1-5-11

Thanks in advance
Avatar of ZeonFlash
ZeonFlash

Have you tried

    Dim s As String = System.Text.Encoding.Default.GetString(userEntry.Properties("objectSid").Value)

(From:  https://www.experts-exchange.com/questions/21061244/Byte-Array-to-String-in-VB.html)
ASKER CERTIFIED SOLUTION
Avatar of oleggold
oleggold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pollin

ASKER

Hello ZeonFlash:

Thanks for your comment.
I tried with that funtion but it shows unreadable data, the same as the one I was using:

                Dim enc As New System.Text.ASCIIEncoding
                Response.Write(enc.GetString(userEntry.Properties("objectSid").Value))

it looks that there are characters with values higher than 127 than cannot be decoded.

Thnks anyway
Avatar of Pollin

ASKER

Hello oleggold

Thanks a lot, these articles are the ones I was looking for.

You are a star!!!