import_results = gpg.import_keys(key_data) what exactly should key_data be

96 views
Skip to first unread message

Greg Reinbach

unread,
Sep 10, 2011, 4:02:13 PM9/10/11
to python-gnupg
I have the public and private key generated on another system as
separate text files and am wanting to import the private key so that I
can decrypt a file that was encrypted with the public key. I'm writing
code that needs to move through various environments (dev, qa, etc).

My thought process was to import the private key, so tried setting the
key_data value to the private key string ('-----BEGIN PGP PRIVATE KEY
BLOCK-----<snip>-----END PGP PRIVATE KEY BLOCK-----')

>>> key_data = '-----BEGIN PGP PRIVATE KEY BLOCK-----<snip>-----END PGP PRIVATE KEY BLOCK-----'
>>> import_result = gpg.import_keys(key_data)
>>> import_result.count
0

So nothing is being imported.

I also tried placing these text files in a specific directory and then
using that dir as for the gnugphome var

>>> import gnupg
>>> gpg = gnupg.GPG(gnupghome='/path/to/keyfiles')
>>> gpg.list_keys()
[]

I'm obviously clueless here, and any help in putting me on the right
track would be greatly appreciated.

Thanks,
Greg

Vinay Sajip

unread,
Sep 10, 2011, 7:01:23 PM9/10/11
to python-gnupg
On Sep 10, 9:02 pm, Greg Reinbach <g...@ironlabs.com> wrote:
> I have the public and private key generated on another system as
> separate text files and am wanting to import the private key so that I
> can decrypt a file that was encrypted with the public key. I'm writing
> code that needs to move through various environments (dev, qa, etc).
>

The test harness (test_gnupg.py, included in the .tar.gz) includes
tests for the import functionality, so you can see what the format is.
Also, if you enable logging, you will see the normally hidden
interactions with gpg (test_gnupg.py does this, and saves the log in
test_gnupg.log).

Regards,

Vinay Sajip

Greg Reinbach

unread,
Sep 11, 2011, 12:08:26 PM9/11/11
to python...@googlegroups.com
Thanks Vinay, just what I needed.

Greg
Reply all
Reply to author
Forward
0 new messages