#!/bin/bash
# ./UUIDgenkey.sh
# Israel Torres [email protected]
# Tue Aug 23 12:53:46 PDT 2011
# UUIDgenkey - For My Eyes Only"
#
# see function usage/example below
#
# this function runs system_profiler to get our version; here we look for Mac OS X
function getOSCheck {
system_profiler SPSoftwareDataType | grep 'System Version' | grep -q 'Mac OS X'
}
# this function gets the Mac's universally unique identifier (UUID) to use as the 36 character password
function getUniqueID {
myUUID=$(system_profiler SPHardwareDataType | grep 'Hardware UUID' | cut -d ':' -f 2 | sed 's/^ *//')
}
# this function assigns a fake UUID to the variable myUUID for demonstration purposes only/testing
function setDEMOUniqueID { # FOR DEMO ONLY
myUUID='01234567-ABCD-0123-ABCD-0123456789AB'
}
# this function encrypts the string using AES-256 using myUUID as the password
function passEncrypt {
PLAIN=$1
SECRET=$(echo $PLAIN | openssl enc -aes-256-cbc -salt -pass pass:$myUUID | xxd -u -p | tr -d '\n')
echo $SECRET
}
# this function decrypts the string using AES-256 using myUUID as the password
function passDecrypt {
CIPHER=$1
SECRET=$(echo $CIPHER | xxd -r -p | openssl enc -d -aes-256-cbc -pass pass:$myUUID)
echo $SECRET
}
# this function exits the shell script if it is a non-Mac OS X system
function validateOS {
getOSCheck; if [ $? -ne 0 ]; then
echo "Mac OS X check failed"
exit 1
fi
}
# this function displays the usage and examples if parameter requirements aren't fulfilled
function usage {
echo "usage: $0 '-e|-d|-r|-f' 'string'"
echo "example: $0 -e encryptstring"
echo "example: $0 -d decryptstring"
echo "example: $0 -r encryptstringwithDEMOUUID"
echo "example: $0 -f decryptstringwithDEMOUUID"
exit 1
}
# this begin the main conditional flow
validateOS
if [ ! $# -ne 2 ]; then
operation=$1
stringvar=$2
if [ $operation == "-e" ]; then
getUniqueID
passEncrypt "$stringvar"
exit $?
fi
if [ $operation == "-d" ]; then
getUniqueID
passDecrypt "$stringvar"
exit $?
fi
if [ $operation == "-r" ]; then
setDEMOUniqueID
passEncrypt "$stringvar"
exit $?
fi
if [ $operation == "-f" ]; then
setDEMOUniqueID
passDecrypt "$stringvar"
exit $?
fi
usage
else
usage
fi
#EOF
Comments
0 B
|👍
/👎