Jump to content

Octet to decimal


backibaxter

Recommended Posts

I'm making a connection to Active Directory using ADODB connection. I can read almost everything from this but some outputs are in an Octet format.

For example objectSID is giving me only a ?.

Is there somebody that knows how to read or convert this?

 

I've found a converter function in ASP maybe someone can translate this to PHP?

 

TXT_ObjectGUID = HexStrToDecStr(OctetToHexStr(objRecordSet.fields("objectSID")))

Function OctetToHexStr(arrbytOctet) 
' Function to convert OctetString (byte array) to Hex string. 
Dim k 
OctetToHexStr = "" 
For k = 1 To Lenb(arrbytOctet) 
OctetToHexStr = OctetToHexStr _ 
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2) 
Next 
End Function 

Function HexStrToDecStr(strSid) 
' Function to convert hex Sid to decimal (SDDL) Sid. 
Dim arrbytSid, lngTemp, j 

ReDim arrbytSid(Len(strSid)/2 - 1) 
For j = 0 To UBound(arrbytSid) 
arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2)) 
Next 

HexStrToDecStr = "S-" & arrbytSid(0) & "-" _ 
& arrbytSid(1) & "-" & arrbytSid(

lngTemp = arrbytSid(15) 
lngTemp = lngTemp * 256 + arrbytSid(14) 
lngTemp = lngTemp * 256 + arrbytSid(13) 
lngTemp = lngTemp * 256 + arrbytSid(12) 

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) 

lngTemp = arrbytSid(19) 
lngTemp = lngTemp * 256 + arrbytSid(18) 
lngTemp = lngTemp * 256 + arrbytSid(17) 
lngTemp = lngTemp * 256 + arrbytSid(16) 

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) 

lngTemp = arrbytSid(23) 
lngTemp = lngTemp * 256 + arrbytSid(22) 
lngTemp = lngTemp * 256 + arrbytSid(21) 
lngTemp = lngTemp * 256 + arrbytSid(20) 

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) 

lngTemp = arrbytSid(25) 
lngTemp = lngTemp * 256 + arrbytSid(24) 

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) 

End Function

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.