You are not logged in.

#1 2006-08-25 21:58:37

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Bash: Passphrase encryption program

Bash: Passphrase encryption program

I wrote this a while back while playing with gpg.

#!/bin/bash
# Passphrase encryption program 
# Created by Dave Crouse 01-13-2006
# Reads input from text editor and encrypts to screen.
clear
echo "         Passphrase Encryption Program";
echo "--------------------------------------------------"; echo "";
which $EDITOR &>/dev/null
  if [ $? != "0" ];
      then
      echo "It appears that you do not have a text editor set in your .bashrc file.";
      echo "What editor would you like to use ? " ;
      read EDITOR ; echo "";
  fi
echo "Enter the name/comment for this message :"
read comment
$EDITOR passphraseencryption
gpg --armor --comment "$comment" --no-options --output passphraseencryption.gpg --symmetric passphraseencryption
shred -u passphraseencryption ; clear
echo "Outputting passphrase encrypted message"; echo "" ; echo "" ;
cat passphraseencryption.gpg ; echo "" ; echo "" ;
shred -u passphraseencryption.gpg ;
exit

After you run the program, it outputs something like this.......

-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: KEY: Linux is cool

jA0EAwMC5l8nNDuWf2lgyaJl2VwbtOWttdVlNC2wtpI22jcRkJOUnph/xzvYoac1
zXznkxunRyT7elT668dTSREdKrZ7H7geGtVkeu2eRFALlXkDVSg5m80nntGzG88r
6UGjqIG3nOjztOOGrOODDTYidCoPYwEAaVZADU827lpycUeqiA9+zH5oQl9eFHEO
cYK9G2LnWR0CMY7KFadocPX3o3u1CBeZJsObTonFIty7FYQ=
=mlIy
-----END PGP MESSAGE-----

The "key" for this message is "Linux is cool" .... of course you wouldn't put the key in the name/comment section like i did, but mine was for illustrative purposes only.

I'm sure the program could be improved, use the temp file/ do more error checking etc... but this was just a "quick-n-dirty" way to create an encrypted message wink

Hope you like it.

Offline

#2 2006-08-26 09:01:22

palandir
Member
Registered: 2006-05-14
Posts: 73

Re: Bash: Passphrase encryption program

I didn't test it, just a style suggestion:

Instead of:

which $EDITOR &>/dev/null
  if [ $? != "0" ];
      then

use:

if [ -z "$EDITOR" ]; then
    # $EDITOR not set

And you don't need "exit" at the end or ";" at the end of a line

Offline

Board footer

Powered by FluxBB