Menu

30 January 2010

How to encrypt and decrypt a directory content using gpg

How to use these simple script

$ ./encryptdir.sh
$ ./decryptdir.sh

Example
$ ./encryptdir.sh /home/narendra/test mypassword
$ ./decryptdir.sh /home/narendra/test mypassword

========== encryptdir.sh =========
#!/bin/bash
SOURCEDIR=$1
PASSWORD=$2
if [ -z $1 ]
then
echo "./encryptdir.sh "
exit 1
fi

if [ -z $2 ]
then
echo "./encryptdir.sh "
exit 1
fi


find "$SOURCEDIR" -not -name "*.gpg" -type f -print |while read Filename ;
do
echo encrypting == "$Filename" ;
gpg -c --passphrase $PASSWORD "$Filename" ;
rm "$Filename";
done
exit 0
========== decryptdir.sh ==========
#!/bin/bash
SOURCEDIR=$1
PASSWORD=$2
if [ -z $1 ]
then
echo "./decryptdir.sh "
exit 1
fi

if [ -z $2 ]
then
echo "./decryptdir.sh "
exit 1
fi


find "$SOURCEDIR" -name "*.gpg" -type f -print |while read Filename ;
do
echo encrypting == "$Filename" ;
gpg --passphrase $PASSWORD "$Filename" ;
rm "$Filename";
done
exit 0

===============================================


┌─────────────────────────┐
│ Narendra Sisodiya ( नरेन्द्र सिसोदिया )
│ Society for Knowledge Commons
│ Web : http://narendra.techfandu.org
└─────────────────────────┘

Click here to download:
encryptdir.sh (0 KB)

Click here to download:
decryptdir.sh (0 KB)

Posted via email from LUG@IITD Community Blog

Post a Comment