LDIFDE and double byte characters
I've been given an LDIF file that has double byte chinese characters in the physicalDeliveryOfficeName attribute.I get:Failed on line 1. The last token starts with 'ï'. If I use -u I get:Failed on line 1. The last token starts with '?'. If I save the file as Unicode I get garbled content in and around the valid address text.Can Active Directory accept these characters? Is there something else I can do to get them imported?
December 31st, 2009 11:01pm

LDIFDE accepts Base64 encoding. I believe you can do this if you represent the entire physicalDeliveryOfficeName attribute value in Base64 encoding. Convert the value to a hex string of bytes and then encode. Base64 encoding converts each group of 3 8-bit bytes into 4 6-bit characters. There are utilities for this conversion.Richard MuellerMVP ADSI
Free Windows Admin Tool Kit Click here and download it now
January 2nd, 2010 2:52am

I've used the crude VBScript program below to convert a hex string of 8-bit bytes into a Base64 encoded string of 6-bit characters. ' HexToBase64.vbs ' VBScript program to convert a hex string into a base64 encoded string. Option Explicit Dim strHexValue strHexValue = Wscript.Arguments(0) Wscript.Echo HexToBase64(strHexValue) Function HexToBase64(strHex) Dim lngValue, lngTemp, lngChar, intLen, k, j, strWord, str64, intTerm intLen = Len(strHex) ' Pad with zeros to multiple of 3 bytes. intTerm = intLen Mod 6 If (intTerm = 4) Then strHex = strHex & "00" intLen = intLen + 2 End If If (intTerm = 2) Then strHex = strHex & "0000" intLen = intLen + 4 End If ' Parse into words of 3 hex bytes. j = 0 strWord = "" HexToBase64 = "" For k = 1 To intLen Step 2 j = j + 1 strWord = strWord & Mid(strHex, k, 2) If (j = 3) Then ' Convert 3 8-bit bytes into 4 6-bit characters. lngValue = CCur("&H" & strWord) lngTemp = Fix(lngValue / 64) lngChar = lngValue - (64 * lngTemp) str64 = Base64(lngChar) lngValue = lngTemp lngTemp = Fix(lngValue / 64) lngChar = lngValue - (64 * lngTemp) str64 = Base64(lngChar) & str64 lngValue = lngTemp lngTemp = Fix(lngValue / 64) lngChar = lngValue - (64 * lngTemp) str64 = Base64(lngChar) & str64 lngValue = lngTemp str64 = Base64(lngValue) & str64 HexToBase64 = HexToBase64 & str64 j = 0 strWord = "" End If Next ' Account for padding. If (intTerm = 4) Then HexToBase64 = Left(HexToBase64, Len(HexToBase64) - 1) & "=" End If If (intTerm = 2) Then HexToBase64 = Left(HexToBase64, Len(HexToBase64) - 2) & "==" End If End Function Function Base64(ByVal lngValue) ' Function to convert base 64 number to Base64 character. Select Case lngValue Case 0 Base64 = "A" Case 1 Base64 = "B" Case 2 Base64 = "C" Case 3 Base64 = "D" Case 4 Base64 = "E" Case 5 Base64 = "F" Case 6 Base64 = "G" Case 7 Base64 = "H" Case 8 Base64 = "I" Case 9 Base64 = "J" Case 10 Base64 = "K" Case 11 Base64 = "L" Case 12 Base64 = "M" Case 13 Base64 = "N" Case 14 Base64 = "O" Case 15 Base64 = "P" Case 16 Base64 = "Q" Case 17 Base64 = "R" Case 18 Base64 = "S" Case 19 Base64 = "T" Case 20 Base64 = "U" Case 21 Base64 = "V" Case 22 Base64 = "W" Case 23 Base64 = "X" Case 24 Base64 = "Y" Case 25 Base64 = "Z" Case 26 Base64 = "a" Case 27 Base64 = "b" Case 28 Base64 = "c" Case 29 Base64 = "d" Case 30 Base64 = "e" Case 31 Base64 = "f" Case 32 Base64 = "g" Case 33 Base64 = "h" Case 34 Base64 = "i" Case 35 Base64 = "j" Case 36 Base64 = "k" Case 37 Base64 = "l" Case 38 Base64 = "m" Case 39 Base64 = "n" Case 40 Base64 = "o" Case 41 Base64 = "p" Case 42 Base64 = "q" Case 43 Base64 = "r" Case 44 Base64 = "s" Case 45 Base64 = "t" Case 46 Base64 = "u" Case 47 Base64 = "v" Case 48 Base64 = "w" Case 49 Base64 = "x" Case 50 Base64 = "y" Case 51 Base64 = "z" Case 52 Base64 = "0" Case 53 Base64 = "1" Case 54 Base64 = "2" Case 55 Base64 = "3" Case 56 Base64 = "4" Case 57 Base64 = "5" Case 58 Base64 = "6" Case 59 Base64 = "7" Case 60 Base64 = "8" Case 61 Base64 = "9" Case 62 Base64 = "+" Case 63 Base64 = "/" End Select End Function For example, the string " A#f gt " in hex is "2041236620677420", and the base64 encoded string is "IEEjZiBndCA=". Richard Mueller MVP ADSI
January 2nd, 2010 5:43am

Sorry, this stuff is not documented very well. If you have base64 encoded values in the ldf file, use two colons instead of one to separate the attribute name from the value (along with the space required before the value). For example:givenName: RobertphysicalDeliveryOfficeName:: IEEjZiBndCA=So the format is the LDAP name of the attribute, two colons, a space and then the base64 encoded value. It's up to you to convert your double byte Chinese characters into hexidecimal characters if you use my script to find the base64 encoded string. Richard MuelerMVP ADSI
Free Windows Admin Tool Kit Click here and download it now
January 2nd, 2010 6:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics