[Gelöst] Probleme mir PyME (GPG)

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Benutzeravatar
draci
User
Beiträge: 53
Registriert: Dienstag 26. September 2006, 18:13

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
Zuletzt geändert von draci am Sonntag 1. Februar 2009, 17:20, insgesamt 2-mal geändert.
Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. - Linus Torvalds

[url]http://groups.google.com/group/pt.comp.so.linux/msg/9eb7db59e32fe08a[/url]

[url=http://www.tty1.net/smart-questions_de.html]Wie man richtig Fragen stellt[/url]
Benutzeravatar
draci
User
Beiträge: 53
Registriert: Dienstag 26. September 2006, 18:13

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
Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. - Linus Torvalds

[url]http://groups.google.com/group/pt.comp.so.linux/msg/9eb7db59e32fe08a[/url]

[url=http://www.tty1.net/smart-questions_de.html]Wie man richtig Fragen stellt[/url]
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

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.
Antworten