Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
DECODE_BASE64(){
# This function takes the encoded output from ldapsearch and decodes it
# It then needs to be "hex-dumped" in order to get it into regular text
# So that we can work with it
OBJECT_ID="$1"
BASE64_DECODED=$(echo $OBJECT_ID | base64 -D)
G=($(echo ${BASE64_DECODED} | hexdump -e '16/1 " %02X"'))
OBJECTGUID="${G[3]}${G[2]}${G[1]}${G[0]}-${G[5]}${G[4]}-${G[7]}${G[6]}-${G[8]}${G[9]}-${G[10]}${G[11]}${G[12]}${G[13]}${G[14]}${G[15]}"
}
# Set our objectGUID that we get from ldapsearch to a variable
TO_BE_DECODED="TE0kyRyv8UCppPeXes5JTg=="
# Send this to our decode function
DECODE_BASE64 $TO_BE_DECODED
# Now echo the result
echo $OBJECTGUID
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment