Core\Ldap\Sid::bytes
$sid->bytes(): bytesReturns the SID in its binary form. Active Directory stores a SID in this form, for example in objectSid.
Use it to compare a SID with the bytes a directory returns, or to store a SID in a database column of type bytes.
Good to know: the result has 8 bytes, then 4 bytes for each number after the authority. A SID with 5 numbers, such as a user's SID, has 28 bytes.
Return value
Returns bytes. The bytes: 8 bytes, then 4 bytes for each number after the authority.
Examples
Show the bytes
<?nvs// Shows the binary form of a SID, written as hex.
var $admins = Core\Ldap\Sid::parse('S-1-5-32-544');// This prints 01020000000000052000000020020000.echo Core\Encoding::toHex($admins->bytes()), "\n";01020000000000052000000020020000Count the bytes
<?nvs// Shows how the length of the bytes grows with the numbers in the SID.
array<string> $texts = ['S-1-1-0', 'S-1-5-32-544', 'S-1-5-21-1004336348-1177238915-682003330-1105'];// This prints 12, 16 and 28.foreach ($texts as string $text) { echo Core\Bytes::length(Core\Ldap\Sid::parse($text)->bytes()), "\n";}121628Compare with stored bytes
<?nvs// Shows how to compare a SID with bytes that were stored earlier.
// These are the bytes of S-1-5-32-544, as a database might return them.bytes $stored = Core\Encoding::fromHex('01020000000000052000000020020000');var $admins = Core\Ldap\Sid::parse('S-1-5-32-544');// The bytes are equal, so this prints match.echo $admins->bytes() == $stored ? 'match' : 'no match', "\n";match