mellin has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Small encryption script
by planetscape (Chancellor) on Apr 04, 2007 at 17:00 UTC | |
|
Re: Small encryption script
by ikegami (Patriarch) on Apr 04, 2007 at 17:27 UTC | |
by roboticus (Chancellor) on Apr 06, 2007 at 04:27 UTC | |
by ikegami (Patriarch) on Apr 06, 2007 at 13:32 UTC | |
|
Re: Small encryption script
by quester (Vicar) on Apr 05, 2007 at 05:48 UTC | |
|
Re: Small encryption script
by diotalevi (Canon) on Apr 04, 2007 at 17:13 UTC | |
|
Re: Small encryption script
by zentara (Cardinal) on Apr 05, 2007 at 11:11 UTC |