def key_imp(self): """Allows for the importing of a PyNaCl style key""" from getpass import getpass from lib.crypto_env import GPG_env cType = GPG_env() gpg, hDir = cType.env() pPass = getpass('Private Key Password?') with open('%s/pKey.gpg' % hDir, 'r') as key: pObj = gpg.decrypt_file(key, passphrase=pPass) return pObj.data
def key_imp(self): """Allows for the importing of a PyNaCl style key""" from getpass import getpass from lib.crypto_env import GPG_env cType = GPG_env() gpg, hDir = cType.env() pPass = getpass('Private Key Password?') with open('%s/pKey.gpg' % hDir, 'r') as key: pObj = gpg.decrypt_file(key, passphrase = pPass) return pObj.data
def key_save(self, privKey): """Allows for the saving of a PyNaCl style key""" import os.path from getpass import getpass from lib.crypto_env import GPG_env cType = GPG_env() gpg, hDir = cType.env() ## Ensure we aren't overwriting a previous key... if os.path.isfile('%s/pKey.gpg' % hDir): print '%s/pKey.gpg currently exists!\nPlease rename or move this key before continuing\n' % hDir exit(1) else: pPass = getpass('Private Key Password?\n') foo = gpg.encrypt(privKey, armor = False, encrypt = False, output = '%s/pKey.gpg' % hDir, passphrase = pPass, symmetric = True)
def key_select(self): """Environment Setup""" import base64, nacl.utils, zlib from lib.keys import PyNaCl_keys from nacl.public import PrivateKey, PublicKey, Box pynacl = PyNaCl_keys() kChoice = raw_input( '[G]enerate a Private Key or [I]mport a Private Key?\n') if (kChoice == 'g' or kChoice == 'G'): privObj, privKey = pynacl.key_gen() kSave = raw_input('\nSave the key? [y/N]\n') if (kSave == 'y' or kSave == 'Y'): print '' pynacl.key_save(privKey) print '\nYour Public Key is:\n%s' % pynacl.key_exp(privObj) elif (kChoice == 'i' or kChoice == 'I'): print '' from lib.crypto_env import GPG_env cType = GPG_env() plainKey = pynacl.key_imp() plainObj = zlib.decompress(base64.b64decode(plainKey)) privObj = PrivateKey(plainObj) print '\nYour Public Key is:\n%s' % pynacl.key_exp(privObj) ## Import partner public key partner_plain = raw_input( '\nEnter Plaintext Public Key of Chat Partner:\n') print '' ## Can probably enclose this within PublicKey() partner_obj = zlib.decompress(base64.b64decode(partner_plain)) partner_enc = PublicKey(partner_obj) ## Create a box for chat return Box(privObj, partner_enc), privObj, partner_enc
def key_save(self, privKey): """Allows for the saving of a PyNaCl style key""" import os.path from getpass import getpass from lib.crypto_env import GPG_env cType = GPG_env() gpg, hDir = cType.env() ## Ensure we aren't overwriting a previous key... if os.path.isfile('%s/pKey.gpg' % hDir): print '%s/pKey.gpg currently exists!\nPlease rename or move this key before continuing\n' % hDir exit(1) else: pPass = getpass('Private Key Password?\n') foo = gpg.encrypt(privKey, armor=False, encrypt=False, output='%s/pKey.gpg' % hDir, passphrase=pPass, symmetric=True)