如何在 Coldfusion 中将 Active Directory objectGUID 转换为 UUID
How to convert Active Directory objectGUID to UUID in Coldfusion
我有一个 CFLDAP 查询 returning objectGUID。如何在 ColdFusion 中将其转换为 8-4-4-4-12 模式的有效 UUID 字符串?
我已经指定了 returnAsBinary="ObjectGUID"
,但是 toString(getLDAP.ObjectGUID)
没有 return 想要的结果。
更新:
我试过 binaryEncode():
<cfset guid = binaryencode(getLDAP.objectguid,"HEX")>
其中 return 个:
18E0CE3388B79C4EA4D73894AE8CD8F6
但我期待这个(由另一个我看不到它们的转换步骤的过程提取和提供)。
3cee018-b788-4e9c-a4d7-3894ae8cd8f6
嗯嗯……虽然不相配,但后半句是一样的。 a4d7-3894ae8cd8f6
。
hummm... the last half is the same
有意思。 link 来自 this thread explains why. Apparently, it is more involved than just converting the binary into hex, in one shot:
- First, know the sequence of the byte index that forms the Dashed String:
[3] [2] [1] [0] - [5] [4] - [7] [6] - [8] [9] - [10] [11] [12] [13] [14] [15]
- Next, apply bit masking to each and every single byte value accessed in the array.
- Follow by converting to the Hex representation of the value.
- Just make sure that the Hex value is a double digit value, meaning instead of "A", it should be "0A"
由于CF的数组是从1开始的,所以只需在位置上加上+1。这会以正确的顺序构建解码后的字符串(没有破折号,您可以使用字符串函数轻松添加它)。
// Get GUID binary
bin = yourQuery.objectGUID[rowNumber];
// Extract bytes in this sequence
order = [4,3,2,1, 6,5, 8,7, 9,10,11,12,13,14,15,16];
// Stores converted bytes
hex = [];
for (pos in order) {
// Apply mask to current byte and convert to hext
arrayAppend(hex, formatBaseN(BitAnd(bin[pos], 255), 16));
}
writeOutput("Hex string = "& arrayToList(hex, ""));
是的...我在一个旧的 CF post 中找到了它,它对我有用:
<CFLDAP ACTION="query" NAME="getLDAP" START="DC=info,DC=sys" SCOPE="subtree" STARTROW="1" maxRows="1"
SERVER="#domainCONTROLLER#" USERNAME="#USERNAME#" PASSWORD="#PASSWORD#" PORT="389" TIMEOUT="60"
ATTRIBUTES="sAMAccountName,mail,name,givenName,middleName,sn,title,department,ObjectGUID"
FILTER="sAMAccountName=#session.username#"
returnAsBinary = "ObjectGUID">
<cfset hexguid = BinaryEncode(getLDAP.objectguid,"Hex")>
<cfset sthex = toString(hexguid)>
<cfset GuidStr = mid(sthex,7,2)>
<cfset GuidStr = GuidStr & mid(sthex,5,2)>
<cfset GuidStr = GuidStr & mid(sthex,3,2)>
<cfset GuidStr = GuidStr & mid(sthex,1,2)>
<cfset GuidStr = GuidStr & mid(sthex,11,2)>
<cfset GuidStr = GuidStr & mid(sthex,9,2)>
<cfset GuidStr = GuidStr & mid(sthex,15,2)>
<cfset GuidStr = GuidStr & mid(sthex,13,2)>
<cfset GuidStr = GuidStr & mid(sthex,17,18)>
<cfset guid = left(GuidStr,8) & "-" & mid(GuidStr,9,4) & "-" & mid(GuidStr,13,4) & "-" & mid(GuidStr,17,4) & "-" & mid(GuidStr,21,18)>
你的更多 eloquent。谢谢!
这是我为 Pentaho Kettle "Modified Javascript" 步骤所做的 javascript 实现。
从Java接收objectGUID
作为byte[16]数组,继续使用Java类进行处理
var b = objectGUID; // JavaArray
// the byte order is: [3] [2] [1] [0] - [5] [4] - [7] [6] - [8] [9] - [10] [11] [12] [13] [14] [15]
var theByteOrder = [3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15];
var ordered = new java.io.ByteArrayOutputStream(16);
theByteOrder.forEach(function(i) {
ordered.write(b[i]);
});
var bb = java.nio.ByteBuffer.wrap(ordered.toByteArray());
bb.order(java.nio.ByteOrder.BIG_ENDIAN);
var uuid = new java.util.UUID(bb.getLong(), bb.getLong());
var GUID = uuid.toString();
它不是 coldfusion 方言,是的,但希望它对扫描网络以解决类似任务的人有用。
我有一个 CFLDAP 查询 returning objectGUID。如何在 ColdFusion 中将其转换为 8-4-4-4-12 模式的有效 UUID 字符串?
我已经指定了 returnAsBinary="ObjectGUID"
,但是 toString(getLDAP.ObjectGUID)
没有 return 想要的结果。
更新:
我试过 binaryEncode():
<cfset guid = binaryencode(getLDAP.objectguid,"HEX")>
其中 return 个:
18E0CE3388B79C4EA4D73894AE8CD8F6
但我期待这个(由另一个我看不到它们的转换步骤的过程提取和提供)。
3cee018-b788-4e9c-a4d7-3894ae8cd8f6
嗯嗯……虽然不相配,但后半句是一样的。 a4d7-3894ae8cd8f6
。
hummm... the last half is the same
有意思。 link 来自 this thread explains why. Apparently, it is more involved than just converting the binary into hex, in one shot:
- First, know the sequence of the byte index that forms the Dashed String:
[3] [2] [1] [0] - [5] [4] - [7] [6] - [8] [9] - [10] [11] [12] [13] [14] [15]
- Next, apply bit masking to each and every single byte value accessed in the array.
- Follow by converting to the Hex representation of the value.
- Just make sure that the Hex value is a double digit value, meaning instead of "A", it should be "0A"
由于CF的数组是从1开始的,所以只需在位置上加上+1。这会以正确的顺序构建解码后的字符串(没有破折号,您可以使用字符串函数轻松添加它)。
// Get GUID binary
bin = yourQuery.objectGUID[rowNumber];
// Extract bytes in this sequence
order = [4,3,2,1, 6,5, 8,7, 9,10,11,12,13,14,15,16];
// Stores converted bytes
hex = [];
for (pos in order) {
// Apply mask to current byte and convert to hext
arrayAppend(hex, formatBaseN(BitAnd(bin[pos], 255), 16));
}
writeOutput("Hex string = "& arrayToList(hex, ""));
是的...我在一个旧的 CF post 中找到了它,它对我有用:
<CFLDAP ACTION="query" NAME="getLDAP" START="DC=info,DC=sys" SCOPE="subtree" STARTROW="1" maxRows="1"
SERVER="#domainCONTROLLER#" USERNAME="#USERNAME#" PASSWORD="#PASSWORD#" PORT="389" TIMEOUT="60"
ATTRIBUTES="sAMAccountName,mail,name,givenName,middleName,sn,title,department,ObjectGUID"
FILTER="sAMAccountName=#session.username#"
returnAsBinary = "ObjectGUID">
<cfset hexguid = BinaryEncode(getLDAP.objectguid,"Hex")>
<cfset sthex = toString(hexguid)>
<cfset GuidStr = mid(sthex,7,2)>
<cfset GuidStr = GuidStr & mid(sthex,5,2)>
<cfset GuidStr = GuidStr & mid(sthex,3,2)>
<cfset GuidStr = GuidStr & mid(sthex,1,2)>
<cfset GuidStr = GuidStr & mid(sthex,11,2)>
<cfset GuidStr = GuidStr & mid(sthex,9,2)>
<cfset GuidStr = GuidStr & mid(sthex,15,2)>
<cfset GuidStr = GuidStr & mid(sthex,13,2)>
<cfset GuidStr = GuidStr & mid(sthex,17,18)>
<cfset guid = left(GuidStr,8) & "-" & mid(GuidStr,9,4) & "-" & mid(GuidStr,13,4) & "-" & mid(GuidStr,17,4) & "-" & mid(GuidStr,21,18)>
你的更多 eloquent。谢谢!
这是我为 Pentaho Kettle "Modified Javascript" 步骤所做的 javascript 实现。
从Java接收objectGUID
作为byte[16]数组,继续使用Java类进行处理
var b = objectGUID; // JavaArray
// the byte order is: [3] [2] [1] [0] - [5] [4] - [7] [6] - [8] [9] - [10] [11] [12] [13] [14] [15]
var theByteOrder = [3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15];
var ordered = new java.io.ByteArrayOutputStream(16);
theByteOrder.forEach(function(i) {
ordered.write(b[i]);
});
var bb = java.nio.ByteBuffer.wrap(ordered.toByteArray());
bb.order(java.nio.ByteOrder.BIG_ENDIAN);
var uuid = new java.util.UUID(bb.getLong(), bb.getLong());
var GUID = uuid.toString();
它不是 coldfusion 方言,是的,但希望它对扫描网络以解决类似任务的人有用。