Seite 1 von 1

[Gelöst] Probleme mir PyME (GPG)

Verfasst: Sonntag 1. Februar 2009, 13:15
von draci
Hallo Leute!
Da meine Versuche mit yaw- bzw. enzPycrypto scheiterten,
habe ich mal das Modul PyMe (http://pyme.sourceforge.net/) getestet. Auf meinem Computer mit installiertem GPG funktioniert das wunderbar.
Meine Versuche PyMe das verzeichnis des GPG programms mit zuteilen funktionieren auf meinem PC einwandfrei.
Aber auf anderen Rechner erhalte ich einen sonderbaren Fehler:

Code: Alles auswählen

Traceback (most recent call last):
  File "<string>", line 19, in <module>
  File "C:\Python25\Programme\gpg-test\buildtest1\out1.pyz/pyme.core", line 61,
in __init__
  File "C:\Python25\Programme\gpg-test\buildtest1\out1.pyz/pyme.errors", line 46
, in errorcheck
pyme.errors.GPGMEError: GPGME: No such file or directory (7,32849)
Exception exceptions.AttributeError: "'module' object has no attribute 'gpgme_la
st_passcb'" in  ignored
Hier noch der Code:

Code: Alles auswählen

# -*- coding: utf-8 -*-
import os
import random
os.environ["GNUPGHOME"] = os.path.join(os.getcwd(),'gpg-lib')#This must be done *before* importing pyme!!
from pyme import core, constants
str_='qwertzuiopüäölkjhgfdsayxcvbnm1234567890!"§$%&/()=?*+~#'+"'"
plaintext = "Hello World!\n"
for i in range(100):
    for y in range(200):
        plaintext+=random.choice(str_)
    plaintext+='\n'
        
        
crypttext = ""
#First set of data
plaindata1 = core.Data(plaintext)
cryptdata1 = core.Data()

cont = core.Context()
cont.set_armor(True) #ASCII

cont.op_keylist_start("[Meine öffentlicher Schlüssel]", 0 )#(Hier 0 wenn auch privater schlüssel 1) 

cont.op_encrypt([cont.op_keylist_next()], 1, plaindata1, cryptdata1)
cryptdata1.seek(0,0)
crypttext = cryptdata1.read()
print "Encrypted Data:\n %s" % crypttext
f=file('test.gpg','w')
f.write(crypttext)
f.close()
raw_input()
:cry:

Wer hat Tips für mich oder weiß die Lösung?

Draci

Verfasst: Sonntag 1. Februar 2009, 17:18
von draci
Lösung selbst gefunden:

Code: Alles auswählen

# -*- coding: utf-8 -*-
import os
import random
import install_gpg


os.environ["GNUPGHOME"] = os.path.join(os.getcwd(),'gpg-lib')#This must be done *before* importing pyme!!

from pyme import core, constants
str_='qwertzuiopüäölkjhgfdsayxcvbnm1234567890!"§$%&/()=?*+~#'+"'"
plaintext = "Hello World!\n"
for i in range(100):
    for y in range(200):
        plaintext+=random.choice(str_)
    plaintext+='\n'
        
        
crypttext = ""
#First set of data
plaindata1 = core.Data(plaintext)
cryptdata1 = core.Data()

cont = core.Context()
cont.set_armor(True) #ASCII

cont.op_keylist_start("[Meine öffentlicher Schlüssel]", 0 )#(Hier 0 wenn auch privater schlüssel 1) 

cont.op_encrypt([cont.op_keylist_next()], 1, plaindata1, cryptdata1)
cryptdata1.seek(0,0)
crypttext = cryptdata1.read()
print "Encrypted Data:\n %s" % crypttext
f=file('test.gpg','w')
f.write(crypttext)
f.close()
raw_input()
Modul install_gpg:

Code: Alles auswählen

# -*- coding: utf-8 -*-
import _winreg as winreg
import os

path=os.path.join(os.getcwd(),'gpg-lib')
exe=os.path.join(path,'gpg.exe')
key = winreg.CreateKey(
    winreg.HKEY_LOCAL_MACHINE,
    r"SOFTWARE\GNU\GnuPG")
try:
    winreg.QueryValueEx(key,"Install Directory")
except:
    winreg.SetValueEx(key, "Install Directory", None, winreg.REG_SZ,path)
    winreg.SetValueEx(key, "gpgProgram", None, winreg.REG_SZ,exe)
winreg.CloseKey(key)
Ganzschöner Aufwand, aber es funzt. :P

Verfasst: Sonntag 1. Februar 2009, 17:26
von Leonidas
Das ist ja wohl das hässlichste Binding zu GPGME was ich je gesehen habe, und der Workaround ist seltsam. Zudem das try-except ohne konkrete Ausnahme ein Problem werden könnte.

Achja, und das ``raw_input()`` am Schluss ist auch irgendwie sinnlos.