Created
October 26, 2012 07:24
-
-
Save jdpaton/3957403 to your computer and use it in GitHub Desktop.
Encrypted file using image steganography
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: [email protected] | |
# COMMANDS | |
# create: Args: <path to image file> <path to plain file> | |
# Encrypts a file using the GPG utility, then zips it up and embeds | |
# it into the image file | |
# open: Args: <path to image file created by this script> | |
# Extracts the file out of the image file using zip, then decrypts it | |
set -e | |
E_BADARGS=65 | |
STORE_DIR=/tmp | |
if [ $# -lt 1 ] | |
then | |
echo "Usage: `basename $0` <open|close> [args]" | |
exit $E_BADARGS | |
fi | |
if [ $1 == "create" ] | |
then | |
EXPECTED_ARGS=3 | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo "Usage: `basename $0` create <path to image> <path to file>" | |
exit $E_BADARGS | |
fi | |
if [ ! -f $2 ] | |
then | |
echo "${2} does not exist" | |
exit 1 | |
elif [ ! -f $3 ] | |
then | |
echo "${3} does not exist" | |
exit 1 | |
fi | |
outfile=$(basename $3).asc | |
imgname=$(basename $2) | |
ret=$(file $2 | grep -qi "image"; echo $?) | |
if [ $ret -ne 0 ] | |
then | |
echo "${2} is not a image file" && exit 1 | |
fi | |
randzip=$RANDOM | |
gpg -aci -o $STORE_DIR/$outfile $3 | |
cd $STORE_DIR | |
zip $randzip.zip $outfile | |
cd - | |
rm -f $outfile | |
cat $2 $STORE_DIR/$randzip.zip >> $STORE_DIR/"new-${imgname}" | |
rm -f $STORE_DIR/$randzip.zip | |
echo | |
echo "Present delivered at ${STORE_DIR}/new-${imgname}" | |
echo | |
elif [ $1 == "open" ] | |
then | |
if [ ! -f $2 ] | |
then | |
echo "${2} does not exist" | |
exit 1 | |
else | |
unzip -d $STORE_DIR $2 || true | |
file=$(find $STORE_DIR/ -maxdepth 1 -type f \( -name "*.asc" -or -name "*.gpg" \)) | |
if [ -z $file ] | |
then | |
echo "Cannot find the unzipped file" | |
exit 1 | |
else | |
echo "Opening ${file}" | |
gpg $file | |
fi | |
fi | |
else | |
echo "Unknown operation: ${1}" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment