gpg --batch -ea -r keyid filename

Henry Hertz Hobbit hhhobbit at securemecca.net
Tue May 15 02:33:45 CEST 2007


Jane Grove wrote:

> Message: 4
> Date: Mon, 14 May 2007 12:51:21 -0500
> From: "jane grove" <grove.jane at gmail.com>
> Subject: Encrypt in Batch Mode with Key ID
> To: gnupg-users at gnupg.org
> Message-ID: <c4fe5a0705141051m79847f7tfdacf80da90b6754 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Hello,
> 
> I tried to use the command:
> 
> gpg --batch -ea -r keyid filename
> 
> to encrypt a file in batch mode with a recipient public key ID. I got
> an "encryption failed: unusable public key" error message.
> 
> Interestingly, when I use the command without batch mode like "gpg -ea
> -r keyid filename", I'm able to encrypt the file.  So the batch mode
> is having problems.
> 
> How can I encrypt the file using recipient public keyid correctly in
> batch mode?

Try:

gpg --batch -ea -r KEYID < filename > filename.asc

On Windows in *.BAT, that would perhaps be best written as
(name the script file pcrypt.bat and put it some place in
your %PATH%).  I leave it to you do add more than one
argument which is best done in VBScript, not BAT.

----------------------------------------------------------
@echo off

REM Add gpg.exe to the path if you did not do already
REM PATH=%PATH%;%ProgramFiles%\Gnu\GnuPG

if "%1" == "" goto instruct

setlocal
if exist %1 (
	if exist %1.asc del %1.asc
	gpg --batch -ea -r KEYID < %1 > %1.asc
) else (
	echo FILE %1 does not exist
)
goto exit

:instruct
echo usage: pcrypt file_to_encrypt

:exit
endlocal
----------------------------------------------------------

You didn't say what platform you are on.  If you are on some sort of
Nix platform, you can use the pcrypt script file in this zipped
folder to automate the encryption (it has MY KEYID, and I tested it
and it WORKS - replace my KEYID with one of your choice):

http://www.securemecca.com/Crypto.zip

MD5:	942e18704f65f14551535c6e086128c3
SHA1:	5b17554888d7ad4fc8376ed71c4a8a92f8ff2888

Check sums were created with the "-b" option on Linux. Since ALL of
files in the folder have only LF rather than CR+LF on the ends of
the files (they were written with the BASH shell in mind), I suggest
using GVim on Microsoft Windows since it is the only editor that I
know about that can see the files (there are probably others):

http://www.vim.org/download.php#pc
http://www.vim.org/

I strongly suggest you get the gvim71.exe unless you are a masochist.
If you don't like tilde backup files, add the following line to the
start vimrc file:

set nobackup

If you or others want it in VBScript, let me know and I will try to
add a VBScript file to do it, if I ever get back on MS-Windows. I
have been on Linux for three plus weeks solid right now.  My Anti-Virus
program is probably so far out of date I will have to reinstall it!

You may have a damaged keyring, or the particular key is munged
(hopefully it isn't yours).  In that case search the archives for
how to clean it up.  There is a lot of good advice on how to do
that from quite a few people.  I would try the batch encrypting
with other keys, and if it works with the other keys but not the
one you are mentioning, then the key is the problem.

HHH



More information about the Gnupg-users mailing list