0

我正在从 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})", 
       "$1-$2-$3-$4-$5"
    )
);

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

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

然后插入反斜杠:

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

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

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

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

 3a1e598e-ab35-cc45-8dca-c5e451adc975

如您所见,高位和低位字节被交换为左边的八个字节,但在右侧相同。这是为什么?这似乎很奇怪......

。R M

4

1 回答 1

1

如果你看这里:

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 个段是与“时间”数据相关的整数/短字节,因此具有字节序,而其他部分只是二进制数据,因此没有。

于 2017-07-30T03:45:41.440 回答