Skip to content

Instantly share code, notes, and snippets.

@calum-github
Last active December 1, 2016 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calum-github/5cec6556bd4c35667448ee4506156ceb to your computer and use it in GitHub Desktop.
Save calum-github/5cec6556bd4c35667448ee4506156ceb to your computer and use it in GitHub Desktop.
#!/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