Java/Apache Directory Studio 中 Active Directory objectUUID 属性的字节顺序

Endianness of Active Directory objectUUID Attributes in Java / Apache Directory Studio

我正在从 Java 连接到 Active Directory 服务器。我添加 属性:

 env.put("java.naming.ldap.attributes.binary", "objectGUID");

然后我像这样读取 objecUUID:

Attribute a = result.getAttributes().get("objectUUID");
byte[] b = (byte[])a.get();

并像这样格式化:

String id = Hex.
    encodeHexString(b).
    replaceAll(
       "(.{8})(.{4})(.{4})(.{4})(.{12})", 
       "----"
    )
);

结果是一个格式很好的 UUID。当我想通过其 UUID 查找条目时,我删除破折号:

id = id.replaceAll("[^a-zA-Z0-9]+", "");

然后插入反斜杠:

id = id.replaceAll("([a-zA-Z0-9]{2,2})", "\\");

这一切都很好。我遇到的问题是 Apache Directory Studio 显示(例如)我用户的 UUID 为:

 8e591e3a-35ab-45cc-8dca-c5e451adc975

我的代码显示了与以下条目相同的 UUID:

 3a1e598e-ab35-cc45-8dca-c5e451adc975

如你所见,左边八个字节的高位字节和低位字节交换了,但右边相同。这是为什么?这看起来很奇怪......

.rm

如果你看这里:

https://en.wikipedia.org/wiki/Universally_unique_identifier

Name                               Length (Bytes) Length (Hex Digits) Contents
time_low                           4              8                   integer giving the low 32 bits of the time
time_mid                           2              4                   integer giving the middle 16 bits of the time
time_hi_and_version                2              4                   4-bit "version" in the most significant bits, followed by the high 12 bits of the time
clock_seq_hi_and_res clock_seq_low 2              4                   1-3 bit "variant" in the most significant bits, followed by the 13-15 bit clock sequence
node                               6              12                  the 48-bit node id

您可以看到前 3 个段 integers/shorts 与 "time" 数据相关,因此具有字节顺序,而其他部分只是二进制数据,因此没有。