Created
October 21, 2014 09:55
-
-
Save maleadt/cbdc3a40bd6abc74dc23 to your computer and use it in GitHub Desktop.
encrypt/decrypt
This file contains hidden or 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 | |
use strict; | |
my $secfile = shift || die("Usage: " . basename($0) . " <filename>\n"); | |
die("Error: encrypted source file does not exist.\n") unless (-f $secfile); | |
my $file = $secfile; | |
$file =~ s/\.gpg$// || die("Error: unrecognized file"); | |
die("Error: decrypting would overwrite existing unencrypted file.\n") if (-f $file); | |
system("gpg", "--decrypt", "--default-recipient-self", "--output", $file, $secfile); | |
die("Error: file has not been decrypted\n") unless (-f $file); | |
unlink($secfile) || die("Error: could not remove encrypted file.\n"); | |
if ($file =~ s/\.dir$//) { | |
die("Error: could not unpack directory due to conflicting pack file.\n") if (-e $file); | |
system("tar", "-xf", "$file.dir", $file); | |
unlink("$file.dir") || die("Error: could not remove directory pack.\n"); | |
} |
This file contains hidden or 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 | |
use strict; | |
use File::Basename; | |
use File::Path 'rmtree'; | |
my $file = shift || die("Usage: " . basename($0) . " <filename>\n"); | |
die("Error: unencrypted source file does not exist.\n") unless (-e $file); | |
if (-d $file) { | |
die("Error: could not pack directory due to conflicting pack file.\n") if (-e "$file.dir"); | |
system("tar", "-cf", "$file.dir", $file) | |
== 0 or die("Error: could not pack directory"); | |
rmtree $file or die("Error: could not remove source directory"); | |
$file .= ".dir"; | |
} | |
my $secfile = $file . '.gpg'; | |
die("Error: encrypting would overwrite existing encrypted file.\n") if (-f $secfile); | |
system("gpg", "--encrypt", "--default-recipient-self", "--output", $secfile, $file); | |
die("Error: file has not been encrypted.\n") unless (-f $secfile); | |
unlink($file) || die("Error: could not remove unencrypted file\n") if (-f $file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment