Skip to content

Commit 1b97e2d

Browse files
Convert base64 to Hex(Object GUID) (#1809)
* Create Code.js * Create README.md * Add Business rule: Add or remove tag to the ticket * Rename code.js to code.js * Rename README.md to README.md * Adding new UI Action: Generate PDF * Adding new UI Action: Generate PDF * Adding new Background script: Bulk Update of Fulfillment Group References in Published KB Articles * Adding new Background script: Bulk Update of Fulfillment Group References in Published KB Articles * Delete Server-Side Components/Background Scripts/Bulk Update of Fulfillment Group References in Published KB Articles directory * Update Script.js * Update README.md * Update README.md * Delete Client-Side Components/UI Actions/Generate PDF directory * Create script.js * Create README.md
1 parent 4d1eee5 commit 1b97e2d

File tree

2 files changed

+95
-0
lines changed
  • Server-Side Components/Script Includes/Convert base64 to Hex (Object GUID)

2 files changed

+95
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Description:**
2+
This Script Include converts a Base64-encoded Active Directory (AD) Object GUID into its corresponding hexadecimal format.
3+
When importing AD objects from an on-premises directory using LDAP, the object GUIDs are typically stored in Base64 format.
4+
However, in OOB integrations such as the AD V2 Spoke, the GUID must be provided in hexadecimal format.
5+
This Script Include bridges that gap by decoding the Base64 string and converting it into the required hex representation.
6+
7+
**Usage:**
8+
Can be used in the LDAP Transofrm scripts to convert the base64 code to HEX code
9+
10+
**Sample:**
11+
12+
var base64Code ='ayn8QMpHEGezHQDdAQZi2g==';
13+
gs.print(new global.LDAP_AD_Utils().base64ToHex(base64Code));
14+
15+
**Output:**
16+
40fc296b-47ca-6710-b31d-00dd010662da
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var LDAP_AD_Utils = Class.create();
2+
LDAP_AD_Utils.prototype = {
3+
initialize: function() {},
4+
5+
base64ToHex: function(str) {
6+
7+
var decoded = GlideStringUtil.base64DecodeAsBytes(str);
8+
9+
var n = decoded.length;
10+
11+
if (n < 16) {
12+
13+
return '';
14+
15+
}
16+
17+
var retVal = '';
18+
19+
retVal = retVal + this.prefixZeros(decoded[3] & 0xFF).toUpperCase();
20+
21+
retVal = retVal + this.prefixZeros(decoded[2] & 0xFF).toUpperCase();
22+
23+
retVal = retVal + this.prefixZeros(decoded[1] & 0xFF).toUpperCase();
24+
25+
retVal = retVal + this.prefixZeros(decoded[0] & 0xFF).toUpperCase();
26+
27+
retVal = retVal + '-';
28+
29+
retVal = retVal + this.prefixZeros(decoded[5] & 0xFF).toUpperCase();
30+
31+
retVal = retVal + this.prefixZeros(decoded[4] & 0xFF).toUpperCase();
32+
33+
retVal = retVal + '-';
34+
35+
retVal = retVal + this.prefixZeros(decoded[7] & 0xFF).toUpperCase();
36+
37+
retVal = retVal + this.prefixZeros(decoded[6] & 0xFF).toUpperCase();
38+
39+
retVal = retVal + '-';
40+
41+
retVal = retVal + this.prefixZeros(decoded[8] & 0xFF).toUpperCase();
42+
43+
retVal = retVal + this.prefixZeros(decoded[9] & 0xFF).toUpperCase();
44+
45+
retVal = retVal + '-';
46+
47+
retVal = retVal + this.prefixZeros(decoded[10] & 0xFF).toUpperCase();
48+
49+
retVal = retVal + this.prefixZeros(decoded[11] & 0xFF).toUpperCase();
50+
51+
retVal = retVal + this.prefixZeros(decoded[12] & 0xFF).toUpperCase();
52+
53+
retVal = retVal + this.prefixZeros(decoded[13] & 0xFF).toUpperCase();
54+
55+
retVal = retVal + this.prefixZeros(decoded[14] & 0xFF).toUpperCase();
56+
57+
retVal = retVal + this.prefixZeros(decoded[15] & 0xFF).toUpperCase();
58+
59+
return retVal.toLowerCase();
60+
61+
},
62+
63+
64+
prefixZeros: function(value) {
65+
66+
if (value <= 0xF) {
67+
68+
return '0' + value.toString(16);
69+
70+
} else {
71+
72+
return value.toString(16);
73+
74+
}
75+
76+
},
77+
78+
type: 'LDAP_AD_Utils'
79+
};

0 commit comments

Comments
 (0)