2014

JanFebMarApr
MayJunJulAug
SepOctNovDec

2013

JanFebMarApr
MayJunJulAug
SepOctNovDec

more...

2011

JanFebMarApr
MayJunJulAug
SepOctNovDec

2010

JanFebMarApr
MayJunJulAug
SepOctNovDec

2009

JanFebMarApr
MayJunJulAug
SepOctNovDec

2008

JanFebMarApr
MayJunJulAug
SepOctNovDec

2007

JanFebMarApr
MayJunJulAug
SepOctNovDec

2006

JanFebMarApr
MayJunJulAug
SepOctNovDec

2005

JanFebMarApr
MayJunJulAug
SepOctNovDec

2004

JanFebMarApr
MayJunJulAug
SepOctNovDec

2003

JanFebMarApr
MayJunJulAug
SepOctNovDec

Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in

If you want to have a file crypted, so that noone can see its contents unless they have the correct password, you can use "gpg" to cypher or decypher it. However, its use is a bit complicated.

So, I decided to write a small shell script, called "gpg-vi", which asks for a password, and lets you edit a file, symmetrically crypted using GnuPG with that password.

The script will not let anyone else in that machine to see the contents of the file, but warning: the script writes the contents of the file in plain in a file in /tmp, so that your user id, or root, can see that file until the edition is finished (or even later, because the contents may still be there in the disk after deleting the file).


New comment

Please, write down your name and what you want to say :-)

Name:
Comment:



Pepa, January 23, 2014

## The product of my hobby, for your entertainment:

# If no filename given, or -h or --help: show usage, exit
[[ "$1" = '-h' ]] || [[ "$1" = '--help' ]] || ! [[ "$1" ]] && { echo "Usage: $0 <filename>" 1>&2; exit 1;}

# Create temporary file, if tempfile is not available: use mktemp
tmp=$(tempfile -p egpg- -s .tmp -d "$HOME" 2>/dev/null || mktemp "$HOME/egpg-XXXXXX.tmp") ||\
{ echo 'temporary file could not be created'; exit 1; }

read -s -u 0 -p 'Please enter passphrase: ' pw
echo -n ' ' # Countering 3 backspacess...

Md5(){
echo $(md5sum "$tmp" 2>/dev/null || md5 "$tmp" 2>/dev/nul) && return
echo "Neither md5sum nor md5 is present"
exit 1
}

if [[ -f "$1" ]]
then # File exists; get password, decrypt if possible, take md5
if ! gpg -q --force-mdc --passphrase-fd 0 -o - "$1" >"$tmp" 2>/dev/null <<<"$pw"
then
rm -f -- "$tmp"
echo "File $1 is not gpg encrypted"
exit 1
fi
MD5OLD=$(Md5)
else # File doesn't exist, see if it can be created
>"$1" || { echo "Can't create file $1"; exit 1;}
fi

# Edit the file (whether it pre-existed or is new), take the md5
"${VISUAL:-${EDITOR:-vi}}" "$tmp"
MD5NEW=$(Md5)

# If no error and the file is changed: encrypt, remove temporary file
! (($?)) && ! [[ "$MD5OLD" = $MD5NEW ]] \
&& gpg -q --force-mdc --passphrase-fd 0 -c -o - "$tmp" >"$1" 2>/dev/null <<<"$pw"
shred -u "$tmp" 2>/dev/null || srm -ll "$tmp" 2>/dev/null || rm -f -- "$tmp"

exit 0