def key_select(self, gpg, mode, mLen): """Obtain keys to work with""" from lib.keys import GPG_keys from lib.IO import GPG_IO from getpass import getpass dCrypt = GPG_IO() GPG = GPG_keys() gpg.encoding = 'utf-8' iKey = raw_input('Are we importing a public key? [y/N]\n') if (iKey == 'n' or iKey == 'N' or not iKey): pass else: if (mode == '-i' or not mode): iKey = dCrypt.irc_in( gpg, 'Enter Public Key to Import\nUse a blank line for EOF', '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n') else: iKey = dCrypt.shell_in( gpg, 'Enter Public Key to Import\nUse *** for EOF') gpg.import_keys(iKey) eKey = raw_input('Are we exporting a public key? [y/N]\n') if (eKey == 'n' or eKey == 'N' or not eKey): pass else: GPG.key_show(gpg) tKey = raw_input('\nEnter Public Key to Export\n') if (mode == '-i' or not mode): IRC = GPG_keys() IRC.key_export(gpg, tKey, mLen) else: exp = gpg.export_keys(tKey) print '\nExported key:\n%s' % exp print '\n' GPG.key_show(gpg) you = raw_input('\nPublic Key ID of Chat Partner?\n') print '' me = raw_input('Private Key ID?\n') print '' gPass = getpass('Private Key Password?\n') print '' return you, me, gPass
def key_select(self, gpg, mode, mLen): """Obtain keys to work with""" from lib.keys import GPG_keys from lib.IO import GPG_IO from getpass import getpass dCrypt = GPG_IO() GPG = GPG_keys() gpg.encoding = 'utf-8' iKey = raw_input('Are we importing a public key? [y/N]\n') if (iKey == 'n' or iKey == 'N' or not iKey): pass else: if (mode == '-i' or not mode): iKey = dCrypt.irc_in(gpg, 'Enter Public Key to Import\nUse a blank line for EOF', '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n') else: iKey = dCrypt.shell_in(gpg, 'Enter Public Key to Import\nUse *** for EOF') gpg.import_keys(iKey) eKey = raw_input('Are we exporting a public key? [y/N]\n') if (eKey == 'n' or eKey == 'N' or not eKey): pass else: GPG.key_show(gpg) tKey = raw_input('\nEnter Public Key to Export\n') if (mode == '-i' or not mode): IRC = GPG_keys() IRC.key_export(gpg, tKey, mLen) else: exp = gpg.export_keys(tKey) print '\nExported key:\n%s' % exp print '\n' GPG.key_show(gpg) you = raw_input('\nPublic Key ID of Chat Partner?\n') print '' me = raw_input('Private Key ID?\n') print '' gPass = getpass('Private Key Password?\n') print '' return you, me, gPass
def gpg(self, gpg, mode, you, me, gPass, mLen): """Encrypt or Decrypt""" from lib.IO import GPG_IO dCrypt = GPG_IO() eCrypt = GPG_IO() gChoice = raw_input('[E]ncrypt or [D]ecrypt\n') print '' if (gChoice == 'E' or gChoice == 'e'): if (mode == '-i' or not mode): ## Shorten the encrypted GPG encrypted = eCrypt.out( gpg, you, 'Enter GPG message to encrypt\nUse a blank line for EOF') encrypted = str( str(encrypted).split('-----BEGIN PGP MESSAGE-----')[1:]) encrypted = '*-%s' % str( encrypted.replace('[', '').replace(']', '').replace( '\'', '').replace('\\n', '').replace( '-----END PGP MESSAGE-----', '-*')) ## Split the string into a list based on mLen sList = [ encrypted[i:i + mLen] for i in range(0, len(encrypted), mLen) ] print 'Your message:\n' for i in sList: print i print '' else: print 'Your message:\n%s' % eCrypt.out( gpg, you, 'Enter GPG message to encrypt\nUse a blank line for EOF') print '' elif (gChoice == 'D' or gChoice == 'd'): if (mode == '-i' or not mode): encrypted = dCrypt.irc_in( gpg, 'Enter GPG message to decrypt\nUse a blank line for EOF', '-----BEGIN PGP MESSAGE-----\n\n', gPass) else: encrypted = dCrypt.shell_in( gpg, 'Enter GPG message to decrypt\nUse *** for EOF') print 'Your message:\n%s\n' % str( gpg.decrypt(encrypted, passphrase=gPass))