Cannot import private key

Scott Armitage mail at
Thu Apr 19 14:38:53 CEST 2012

On Thu, 19 Apr 2012 12:39:22 +0200, Peter C. Dietrich
<peter.c.dietrich at> wrote:
> On Wed, 18 Apr 2012 23:13:27 +0200, Scott Armitage <mail at> wrote:
>> gpg --export-secret-key -a <key_id> > private.asc
> I think you should try to export the private key unarmored, i.e. leave out
> the -a option. This should work.

Thanks, Peter; I tried that, but couldn't get it to work either.

I think I have solved the problem though (I still need to try and
reproduce it from scratch, to verify my theory). It seems that
Powershell uses UCS-2 character encoding when using redirectors (the
">" in my commands). Changing the file encoding to ANSI or UTF-8
allows the private key to be imported properly. It is unclear to me
why the public key would import fine, however.

For the record, I was using redirectors instead of the "-o" option
because apparently it has no effect (at least in Powershell on
Windows) if you use it after the --export option. I have now figured
out that I can use "-ao <file.asc>" before the "--export-secret-key
<key_id>" and everything works fine:

gpg -ao private.asc --export-secret-key <key_id>
gpg --import private.asc
gpg: key <key_id>: already in secret keyring
gpg: Total number processed: 1
gpg:       secret keys read: 1
gpg:  secret keys unchanged: 1

Thanks for the help!

More information about the Gnupg-users mailing list