Thanks veedar. I'll start from scratch and see what happens.
Main Topics
Browse All TopicsFedora C2.
I need to encrypt a file received by a CGI script and be able to decrypt it later. I need these processes automated.
I have made the following test script that I hoped would do both and can be split later:
#!/bin/bash
rm -f encrypted
cat phrase | gpg --batch --passphrase-fd 0 --output encrypted --encrypt unencrypted.txt
cat phrase | gpg --batch --passphrase-fd 0 --output decrypted --decrypt encrypted
"phrase" is a file containing a 32 bytes passphrase.
The encryption is working but the decryption is not, if I try to include -c or --symmetric in the first line then it doesn't work either.
gpg: encrypted with 1024-bit ELG-E key, ID 96C7D90C, created 2005-08-11
".........................
gpg: public key decryption failed: bad passphrase
gpg: decryption failed: secret key not available
Questions:
1) can anyone correct the script? I have created a pair of asymmetric keys and it looks like the script is using it when I probably need it to use the symmetric key from the passphrase.
2) how can I suppress all comments? I thought --batch would do that.
Thank you for your help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I have deleted the keys because the asymmetric encryption didn't work, but the commands you mentioned showed the keys before I deleted them. I have kernel 2.6.12.3 and I think I have a recent version of GPG.
It looks like because I want to be able to encrypt and decrypt, the symmetric encryption is a lot easier to use, the asymmetric encryption may require the use of some tricks (pretending to send and receive the encrypted file or something).
I just found the commands below work (no keys at all exist) and I think I'll leave it at that.
Thank you very much for your persistence.
gpg --symmetric --batch --passphrase-fd 0 <pass --output encrypted encrypt
gpg --batch --passphrase-fd 0 <pass -d --output decrypted encrypted
"pass" is the file containing the passphrase
encrypt is the file to encrypt
encrypted is the output file of the encryption command
decrypted is the output file of the decrypting command
Hope this helps somebody.
I installed gpg 1.4.2, and generated the keys, here is the result:
gpg: key 79E7ACD4 marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 1024D/79E7ACD4 2005-08-17
Key fingerprint = 9E1A EF32 CE60 47AC 282D 4560 1704 4D36 79E7 ACD4
uid myname (mycomment) <myname@myisp.com>
sub 2048g/62C0E506 2005-08-17
The result is different when using the commands in the initial post above.
I get the following message after commenting out the decryption line.
myname@myisp.com: skipped: public key not found
gpg: unencrypted.txt: encryption failed: public key not found
The passphrase entered when generating the keys is the same than the one contained in the file "phrase".
Running it from the console gives me a different result:
cat phrase | gpg --batch --passphrase-fd 0 --output encrypted --encrypt -r myname minicom.log
cat phrase | gpg --batch --passphrase-fd 0 --output decrypted --decrypt encrypted
gpg: encrypted with 2048-bit ELG-E key, ID 1B5DF7E9, created 2005-08-17
"myname (mycomment) <myname@myisp.com>"
Did you try running the commands from the console instead of a script ? There are environment differences between a script and the command line.
more efficiently:
recreate a key pair (--gen-key) then crypt w your public key, using
'gpg -q -e -r YourKeyID FileName'
this way you won't have to let any password on the machine running the script. keep a copy of your secret key file (probably ~/.gnupg/secring.gpg) in a multiple VERY safe places away from the machine (think flood and fire) and DO NOT forget your passphrase to it
Business Accounts
Answer for Membership
by: veedarPosted on 2005-08-15 at 17:03:28ID: 14679080
Not sure where you went wrong but here's what worked for me.
"
Create a key first with...
gpg --gen-key
...I used the example from the docs to create a key and assign a passphrase like this
USER-ID: "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>
I then used it successfully with the -r option like so...
cat phrase | gpg --batch --passphrase-fd 0 --output encrypted --encrypt -r heinrichh@duesseldorf.de unencrypted.txt
cat phrase | gpg --batch --passphrase-fd 0 --output decrypted --decrypt -r heinrichh@duesseldorf.de encrypted