Created
August 1, 2010 18:01
-
-
Save goerz/503584 to your computer and use it in GitHub Desktop.
encrypt.pl, decrypt.pl: Two scripts that encrypt, and decrypt files using GPG
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
#!/usr/bin/perl -w | |
use strict; | |
my $recursive = 'false'; | |
if ($ARGV[0] eq '-r') { | |
$recursive = shift @ARGV; | |
$recursive = 'true'; | |
} | |
decrypt(\@ARGV); | |
sub decrypt{ | |
my $filelist = shift; | |
foreach my $file (@{$filelist}){ | |
if ( (-f $file) && ($file =~ /\.gpg$/) ){ | |
print "\n\nDecrypting $file\n"; | |
system('gpg "'."$file".'"'); | |
my $newfile = $file; | |
$newfile =~ s/\.gpg$//; | |
if (-e $newfile){ | |
system('rm "'."$file".'"'); | |
} else { | |
warn("Decryption of $file was NOT successful\n"); | |
} | |
} | |
if ( (-d $file) && ($recursive eq 'true') ){ | |
my @recfilelist; | |
if ($file =~ /[ ]/){ | |
@recfilelist = glob('./"'."$file".'"/*'); | |
} else { | |
@recfilelist = glob("./$file/*"); | |
} | |
decrypt(\@recfilelist); | |
} | |
} | |
} |
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
#!/usr/bin/perl -w | |
use strict; | |
my $recursive = 'false'; | |
if ($ARGV[0] eq '-r') { | |
$recursive = shift @ARGV; | |
$recursive = 'true'; | |
} | |
encrypt(\@ARGV); | |
sub encrypt{ | |
my $filelist = shift; | |
foreach my $file (@{$filelist}){ | |
if ( (-f $file) && (!(-e "$file.gpg")) && (!($file =~ /\.gpg$/)) ){ | |
print "Encrypting $file ... \t"; | |
system('gpg -e -r "Michael Goerz Local Encryption" "'."$file".'"'); | |
if (-e "$file.gpg"){ | |
print "Wiping $file\n"; | |
system('wipe "'."$file".'"'); | |
} else { | |
print "\n\n"; | |
warn("Encryption of $file was NOT successful\n"); | |
} | |
} | |
if ( (-d $file) && ($recursive eq 'true') ){ | |
my @recfilelist; | |
if ($file =~ /[ ]/){ | |
@recfilelist = glob('./"'."$file".'"/*'); # TODO: check if ./ can be removed | |
} else { | |
@recfilelist = glob("./$file/*"); | |
} | |
encrypt(\@recfilelist); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment