views:

88

answers:

1

I tried to use the gnupg.py module encryption decryption function named
" def test_encryption_and_decryption(self): "

Could i use this function by passing the key or fingerprint retrieved from public key server.

I am getting the key by this :

retk = urllib.urlopen('http://pool.sks-keyservers.net:11371/pks/lookup
op=get&search=hex format of key')
pub_key = retk.read()

i also tried to pass the fingerprint in encrypt method :

data = "Hello, world!"
edata = str(self.gpg.encrypt(data, fingerprint))
print edata

Not getting the way how to do .Is somebody help me out by giving their valuble and effective solution/suggestions.

thanks!

+2  A: 

Before you can encrypt with a key whose keyid you have, you need to import the key into the keyring. Use the import_keys function for that.

Edit: that you cannot encrypt even after importing the key is because GPG does not trust it. This becomes apparent when you turn on verbose messages; you'll get

gpg: <keyid>: There is no assurance this key belongs to the named user

To work around (short of setting up a trust path for the key), you can change gpg's trust model. The following program works for me (with my key as an example)

import gnupg, urllib
retk = urllib.urlopen("http://keyserver.pramberger.at/pks/"
       "lookup?op=get&search=0x6AF053F07D9DC8D2")
pub_key = retk.read()

gpg = gnupg.GPG(gnupghome="/tmp/foo", verbose=True)
print "Import:", gpg.import_keys(pub_key).summary()
print "Encrypt:", gpg.encrypt("Hello, world!", "6AF053F07D9DC8D2", 
                  always_trust=True)
Martin v. Löwis
thanks ... yes definately!but the function giving 'FAIL'error when key i importing the key
jaysh
Then your key may not be in the correct format or corrupted. It needs to be in the same format as if you generate a key and then export it.
Vinay Sajip