I need to place info in scripts that shouldn't be readily obvious. This isn't encryption, it's just obfuscation. Some of the inspiration for this came from random readings of bash manuals and discussions and one part directly from http://www.commandlinefu.com/commands/view/6066/convert-ascii-string-to-hex. Because of a personal preference to awk, I converted the commands.
To Hide Varables
Run the following command with the command or info you want obscured.
1 ) encode the STRINGTOHIDE
echo "STRINGTOHIDE" | base64 -w 0
U1RSSU5HVE9ISURFCg==
2) encode the varable
echo -n 'HIDDENVARABLE="`echo U1RSSU5HVE9ISURFCg== | base64 -di`"' | xxd -ps | awk '{gsub(/[[:xdigit:]]{2}/,"\\x&");print}'
To Hide Varables
Run the following command with the command or info you want obscured.
1 ) encode the STRINGTOHIDE
echo "STRINGTOHIDE" | base64 -w 0
U1RSSU5HVE9ISURFCg==
2) encode the varable
echo -n 'HIDDENVARABLE="`echo U1RSSU5HVE9ISURFCg== | base64 -di`"' | xxd -ps | awk '{gsub(/[[:xdigit:]]{2}/,"\\x&");print}'
\x48\x49\x44\x44\x45\x4e\x56\x41\x52\x41\x42\x4c\x45\x3d\x22\x60\x65\x63\x68\x6f\x20\x55\x31\x52\x53\x53\x55\x35\x48\x56
\x45\x39\x49\x53\x55\x52\x46\x43\x67\x3d\x3d\x20\x7c\x20\x62\x61\x73\x65\x36\x34\x20\x2d\x64\x69\x60\x22
\x45\x39\x49\x53\x55\x52\x46\x43\x67\x3d\x3d\x20\x7c\x20\x62\x61\x73\x65\x36\x34\x20\x2d\x64\x69\x60\x22
3) check it
eval $'\x48\x49\x44\x44\x45\x4e\x56\x41\x52\x41\x42\x4c\x45\x3d\x22\x60\x65\x63\x68\x6f\x20\x55\x31\x52\x53\x53\x55\x35\x48\x56\x45\x39\x49\x53\x55\x52\x46\x43\x67\x3d\x3d\x20\x7c\x20\x62\x61\x73\x65\x36\x34\x20\x2d\x64\x69\x60\x22'
echo $'HIDDENVARABLE'
HIDDENVARABLE
To hide a command,
1)
echo -n 'HIDDENCOMMAND' | xxd -ps | awk '{gsub(/[[:xdigit:]]{2}/,"\\x&");print}'
echo -n 'ls -lah' | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g'
\x6c\x73\x20\x2d\x6c\x61\x68
eval $'\x6c\x73\x20\x2d\x6c\x61\x68'
eval $'hex string'