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
Visual Basic.NET

Avatar of undefined
Last Comment
Pollin

8/22/2022 - Mon
ZeonFlash

Have you tried

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

(From:  https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21061244.html)
ASKER CERTIFIED SOLUTION
oleggold

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Pollin

ASKER
Hello oleggold

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

You are a star!!!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy