Wednesday, April 22, 2009

Decrypting multiple files with GnuPG

Here's a simple UNIX/Linux script that asks for a password and then decrypts a batch of files using that password, using GnuPG:


echo -n "Enter password: "
stty -echo
read password
stty echo

for encrypted in *.gpg; do
decrypted=`echo ${encrypted} | sed s/.gpg\$//`
echo -n ${decrypted}
echo "${password}" | gpg --passphrase-fd 0 -o "${decrypted}" -d "${encrypted}" > /dev/null 2> /dev/null
if [ "$?" = "0" ]; then
chmod 600 "${decrypted}"
echo " [ DONE ]"
echo " [ FAILED ]"

1 comment:

  1. or you can use...

    gpg --decrypt --multifile *.gpg

    or even better

    gpg --decrypt-files *.gpg

    which is more secure than passing your passphrase to stdout