Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

crypt_edit.pl

by ichimunki (Priest)
on Oct 10, 2001 at 03:00 UTC ( #117890=sourcecode: print w/ replies, xml ) Need Help??

Category: Cryptography
Author/Contact Info x@ichimunki.com
Description: Extremely light-weight Tk text editor that saves text to an encrypted file using GnuPG or PGP (or any other reasonably similar encryption utility). Does not yet include the ability to sign text. Will not protect you from keyboard sniffers, shared memory issues, x-ray vision, or users of PSI::ESP. This script's only intent is to make it possible to type some text and encrypt it to disk without first having to save the text to a file. Saving the plain text to a file may be fine for information in transit, but if your machine starts out secure, but is later compromised, data that was stored in a non-encrypted state may be recoverable. I realize that there are some privacy modules on CPAN and that I did not use them. They can be difficult to install, and as far as I know will not enhance the security of this script.
#!/usr/bin/perl -w
use strict;
use Tk;

=head1 NAME

crypt_edit.pl

=head1 VERSION

0.1 (alpha)

=head1 SYNOPSIS

CryptEdit provides a quick text edit environment which saves directly
to an encrypted file, which removes the incredibly insecure step of
saving the text to a file on disk and then encrypting from there.

=head1 AUTHOR

Michael Libby
x@ichimunki.com

=head1 USAGE

C<crypt_edit.pl>

The program is set to use GnuPG using a keyring in a default location
(or with an options file readable from the default location. (I have
also included a sample that will use a keyring located on a floppy
disk on a Windows machine). You may need to alter the $PRIV_CMD to
operate with your install of PGP or GnuPG.

Enter a valid pathname/filename.  Enter a recipient name.

Type your text (or even use cut and paste to insert text from
elsewhere), click the "Encrypt to File" button. Viola!

=cut

#user settings
#$PRIV_CMD must have a trailing space!
my $PRIV_CMD = "gpg ";
#my $PRIV_CMD = "pgp ";
#my $PRIV_CMD = "gpg --homedir A: ";

#construct the application window
my $mw = Tk::MainWindow->new();

#create action buttons
my $button_bar = $mw->Frame()->pack( -expand => 1, -fill => 'x');

my $button_encrypt = 
    $button_bar->Button( -text => 'Encrypt to File', 
              -command => \&encrypt_to_file );

my $button_exit =
    $button_bar->Button( -text => 'Exit',
              -command => \&exit_app );

$button_encrypt->pack( -side => 'left' );
$button_exit->pack( -side => 'left' );

#create entry fields
my $name_frame = $mw->Frame()->
    pack( -expand => 1, 
      -fill => 'x'
      );
my $name_label = $name_frame->Label( text => 'Filename:')->
    pack( -side => 'left' );
my $name_entry = $name_frame->Entry()->
    pack( -side => 'right', 
      -fill => 'x', 
      -expand => 1 
      );

my $recip_frame = $mw->Frame()->
    pack( -expand => 1, 
      -fill => 'x'
      );
my $recip_label = $recip_frame->Label( text => 'Recipient:')->
    pack( -side => 'left' );
my $recip_entry = $recip_frame->Entry()->
    pack( -side => 'right', 
      -fill => 'x', 
      -expand => 1
      );

#create main text area
my $text_box = 
    $mw->Scrolled( 'Text', 
           '-scrollbars' => 'e',
           )->
    pack();

MainLoop;

sub encrypt_to_file
{
    #get privacy call command
    my $priv_call = $PRIV_CMD;
    $priv_call .= "-r " . $recip_entry->get() . " ";
    $priv_call .= "-o " . $name_entry->get() . " ";
    $priv_call .= "--encrypt ";

    #get text
    my $text = $text_box->get('1.0', 'end');

    #open pipe to privacy command
    open( PRIVACY, "| $priv_call");
    print PRIVACY $text;
    close PRIVACY;
}

sub exit_app
{
    #add check if text changed since last saved or signed?
    exit;
}

=head1 COPYRIGHT

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA

Also available in full at http://www.gnu.org/licenses/gpl.html

=cut

Comment on crypt_edit.pl
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://117890]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-07-14 03:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls