encrypt 1.3 KB

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