Skip to content

Instantly share code, notes, and snippets.

@mjf
Last active August 29, 2015 13:59
Show Gist options
  • Save mjf/10715695 to your computer and use it in GitHub Desktop.
Save mjf/10715695 to your computer and use it in GitHub Desktop.
encdec-tools - Ecrypt file and decript, typeset and search encrypted file
#! /bin/sh
# dec - Decrypt encrypted file
# Copyright (C) 2014 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
ENC_CIPHALG="${ENC_CIPHALG:-aes-256-cbc}"
ENC_FILEEXT="${ENC_FILEEXT:-enc}"
if [ $# -ne 1 ]
then
echo 'Usage: dec FILE' 1>&2
exit 1
fi
file="$1"
deccat "$file" > "$file"
#! /bin/sh
# deccat - Catenate encrypted file
# Copyright (C) 2014 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
ENC_CIPHALG="${ENC_CIPHALG:-aes-256-cbc}"
ENC_FILEEXT="${ENC_FILEEXT:-enc}"
if [ $# -ne 1 ]
then
echo 'Usage: deccat FILE' 1>&2
exit 1
fi
file="$1"
openssl "$ENC_CIPHALG" -d -a -salt -in ."$file.$ENC_FILEEXT"
#! /bin/sh
# decgrep - Search encrypted file
# Copyright (C) 2014 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
if [ $# -ne 2 ]
then
echo 'Usage: decgrep PATTERN FILE' 1>&2
exit 1
fi
pattern="$1"
file="$2"
deccat "$file" | grep -i "$pattern"
#! /bin/sh
# end - Encrypt file
# Copyright (C) 2014 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
ENC_CIPHALG="${ENC_CIPHALG:-aes-256-cbc}"
ENC_FILEEXT="${ENC_FILEEXT:-enc}"
if [ $# -ne 1 ]
then
echo 'Usage: enc FILE' 1>&2
exit 1
fi
file="$1"
if openssl "$ENC_CIPHALG" -a -salt -in "$file" -out ."$file.$ENC_FILEEXT"
then
rm -i "$file"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment