Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

by ichimunki (Priest)
on Oct 10, 2001 at 03:00 UTC ( #117890=sourcecode: print w/replies, xml ) Need Help??
Category: Cryptography
Author/Contact Info
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

=head1 VERSION

0.1 (alpha)


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

=head1 USAGE


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!


#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',


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?


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
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

Also available in full at

Replies are listed 'Best First'.
Re: - a VIM alternative
by anthony_thyssen (Initiate) on Apr 01, 2016 at 01:58 UTC

    Nice idea... Though I found it easier to get VIM to decrypt and encrypt files in memory when it needs to read/write them.

    Look at and search for "VIM". Can use openssl, GPG, or other encryption software with 'pipeline' capability.

    Anthony Thyssen

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-01-22 04:36 GMT
Find Nodes?
    Voting Booth?