encrypt
1	#!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my $file;
7 if ( ! defined $ARGV[0] ) {
8 print "Enter file path to encrypt: ";
9 my $input = <STDIN>;
10 chomp $input;
11 $file = $input;
12 } else {
13 # Expects full path of file
14 $file = $ARGV[0];
15 }
16
17 if ( ! -f $file ) { die "File argument must be a plain file, $file is not a plain file or it cannot be found, exiting...\n" };
18
19 system("gpg --symmetric --no-symkey-cache --cipher-ago AES-256 $file") == 0 or die "Something went wrong with GPG, I didn't encrypt the file...";
20
21 print "Looking for encrypted file..\n";
22 my $newFilename = $file . ".gpg";
23 if ( -f $newFilename ) {
24 print "Encrypted file is at: $newFilename\n";
25 } else {
26 print "Something went wrong? I couldn't find the encrypted file, maybe check the dir?\n";
27 exit 1;
28 }
29
30 if ( ! defined $ARGV[1] ) {
31 print "Want to delete the unencrypted file? (y/n)\n";
32 my $input = <STDIN>;
33 chomp $input;
34 if ( $input eq "y" ) {
35 print "Deleting $file ..\n";
36 system("rm $file") == 0 or print "Something went wrong, didn't delete old file\n";
37 } elsif ( $input eq "n" ) {
38 print "Not deleting $file .. \n";
39 } else {
40 print "Didn't recognize your input, skipping..\n";
41 }
42 } elsif ( defined $ARGV[1] && $ARGV[1] eq "--delete" ) {
43 print "Deleting $file ..\n";
44 system("rm $file") == 0 or print "Something went wrong, didn't delete old file\n";
45 }