What do you think about a script that has two options; encrypt and view encrypted file? I created the script below to view my password file (normal text file) encrypted with Crypt::RC4 while on the road. I simply go to the terminal and type "./passwords.pl view <passwordfile> <password>" to see my passwords, in case i forgot them while away from home.
i know some operating systems store command history effectively caching my password as well, but i will change that in the future so that the script itself asks the password to use.
#!/usr/bin/perl -w use strict; use Crypt::RC4; print "usage: $0 [ crypt | view ] <filename> <password>\n" and exit un +less validateInput(@ARGV); my ($option, $file, $password) = @ARGV; my ($plaintext, $crypted, $decrypted); $plaintext = openFile($file); if ($option eq 'view') { $decrypted = RC4($password, $plaintext); print "$decrypted\n"; } elsif ($option eq 'crypt') { my $outputname = "$file" . '.enc'; $crypted = RC4($password, $plaintext); open FH, ">$outputname" or print "error: $!\n" and exit; print FH "$crypted"; close FH; print "$file encrypted with the given password\nnew filename $output +name\n"; } sub openFile { my $filename = shift; my $data; open FH, "<$filename" or print "error: $!\n" and exit; while (<FH>) { $data .= $_; } close FH; return $data; } sub validateInput { return undef unless @_ == 3; return undef unless ($_[0] =~ /view|crypt/); return undef unless (-e $_[1]); 1; }
In reply to Small encryption script by mellin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |