![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Gnupg | mile1982 | UNIX for Dummies Questions & Answers | 2 | 08-31-2008 02:48 AM |
| Help Required: Command to find IP address and command executed of a user | loggedout | Security | 2 | 08-06-2008 09:12 PM |
| Problem with GnuPG...need help | manas_ranjan | Shell Programming and Scripting | 0 | 08-29-2007 05:09 AM |
| inconsistent ls command display at the command prompt & running as a cron job | rajranibl | SuSE | 5 | 07-30-2007 09:26 AM |
| How to use more than one MPE command STREAM with Unix command in a single shell? | bosskr | Shell Programming and Scripting | 0 | 09-19-2006 10:44 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
GnuPG (gpg command)
I've been blessed with the task of writing functions that will be used to encrypt / decrypt data files using the Gnupg (gpg command) software on our Solaris 9. This was just installed last friday and I've got no documentation other than what I've found on the web.
I was successful in writing and testing the encrypt_file function. Piece of cake. The problem I have is with the decrypt_file function trying to get the gpg command to allow me to pass the 'passphrase' as a variable. I can run the command (without a script), it prompts me for the passphrase, I type it and it works. I'm confused about the --command-fd and --passphrase-fd options. I've tried with each seperately and each alone and still get an error saying 'bad passphrase'. Has anyone else tried this? What have I got wrong? My current script and its output follows. #! /bin/ksh #------------------ function decrypt_file { # This function uses the GnuPG (gpg command) to decrypt files # $1.gpg will be the input file and the output will be called $1. # The gpg command resides in /usr/local/bin #Setup B=/bin U=/usr/local/bin # this is where the gpg executable is # Check if the input file exists if [[ ! -f $1.gpg ]] then echo "-*- Error - $1.gpg not found" return 1 fi # Delete the output file (if one exists) $B/rm -f $1 # Let's decrypt the file PP=`echo 'this is my test passphrase'` # this and the next line will be echo "Pp=$PP" # replaced by an environment variable echo $PP| $U/gpg --command-fd 0 --passphrase-fd 0 \ --decrypt-files "$1.gpg" << !end \ > /tmp/$$data !end stat=$? if [[ $stat != 0 ]] then echo "-*- Error - decrypt (gpg) failed" return 1 fi $B/grep -i "ERROR" /tmp/$$data > /dev/null stat=$? if [[ $stat != 1 ]] then echo "-*- Decrypt failed" cat /tmp/$$data return 1 fi # Look's like we're good to go echo "--- File $1.gpg successfully de-encrypted as $1" # Remove the input-file (the point of the whole process) and /tmp files $B/rm -f $1.gpg $B/rm -f /tmp/$$* return 0 } # end decrypt_file #------------------ Here's what I get when I run it: $: decrypt_file test-file.txt Pp=this is my test passphrase gpg: WARNING: using insecure memory! gpg: please see http://www.gnupg.org/faq.html for more information Reading passphrase from file descriptor 0 You need a passphrase to unlock the secret key for user: "test name (test comment) <testemail@pni.com>" 1024-bit ELG-E key, ID 84D710AC, created 2006-01-13 (main key ID F423056A) gpg: encrypted with 1024-bit ELG-E key, ID 84D710AC, created 2006-01-13 "test name (test comment) <testemail@pni.com>" gpg: public key decryption failed: bad passphrase gpg: decryption failed: secret key not available -*- Error - decrypt (gpg) failed $: Thanks, in advance, for any help you can give me. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|