Esempio n. 1
0
	def execute(self, argv):
		args = self._parse_argv(argv)
		pycrypter = PyCrypter()

		if len(args) > 0:
			action = args['action']

			if action == 'new':
				keys = pycrypter.new()
				print "PUBLIC: %s" % keys['public']
				print
				print "PRIVATE: %s" % keys['private']
				print

			elif action == 'encrypt':
				msg = pycrypter.encrypt(args['-k'], args['-m'])
				print msg

			elif action == 'decrypt':
				msg = pycrypter.decrypt(args['-k'], args['-m'])
				print msg

			else:
				self.help()

		else:
			self.help()
Esempio n. 2
0
    def __init__(self, parent=None):
        Parent_cls.__init__(self, parent)

        self.ui = UI_cls()
        self.ui.setupUi(self)

        self.setWindowTitle('Pycrypter')
        self.setWindowIcon(QIcon(ICON_PATH))

        self.connect(self.ui.generateButton, SIGNAL("clicked()"), self.generateButtonClick)
        self.connect(self.ui.toPublicButton, SIGNAL("clicked()"), self.toPublicButtonClick)
        self.connect(self.ui.toPrivateButton, SIGNAL("clicked()"), self.toPrivateButtonClick)
        self.connect(self.ui.encryptButton, SIGNAL("clicked()"), self.encryptButtonClick)
        self.connect(self.ui.decryptButton, SIGNAL("clicked()"), self.decryptButtonClick)
        self.connect(self.ui.getlocalButton, SIGNAL("clicked()"), self.getlocalButtonClick)
        self.connect(self.ui.updatelocalButton, SIGNAL("clicked()"), self.updatelocalButtonClick)

        self.pycrypter = PyCrypter()

        self.getlocalButtonClick()
Esempio n. 3
0
class GuiQt(Parent_cls):
    def __init__(self, parent=None):
        Parent_cls.__init__(self, parent)

        self.ui = UI_cls()
        self.ui.setupUi(self)

        self.setWindowTitle('Pycrypter')
        self.setWindowIcon(QIcon(ICON_PATH))

        self.connect(self.ui.generateButton, SIGNAL("clicked()"), self.generateButtonClick)
        self.connect(self.ui.toPublicButton, SIGNAL("clicked()"), self.toPublicButtonClick)
        self.connect(self.ui.toPrivateButton, SIGNAL("clicked()"), self.toPrivateButtonClick)
        self.connect(self.ui.encryptButton, SIGNAL("clicked()"), self.encryptButtonClick)
        self.connect(self.ui.decryptButton, SIGNAL("clicked()"), self.decryptButtonClick)
        self.connect(self.ui.getlocalButton, SIGNAL("clicked()"), self.getlocalButtonClick)
        self.connect(self.ui.updatelocalButton, SIGNAL("clicked()"), self.updatelocalButtonClick)

        self.pycrypter = PyCrypter()

        self.getlocalButtonClick()


    def __del__(self):
        self.ui = None


    def closeEvent(self, e):
        sys.exit(0)


    def generateButtonClick(self):
        keys = self.pycrypter.new()
        self.ui.publicEdit.setText(keys['public'])
        self.ui.privateEdit.setText(keys['private'])


    def toPublicButtonClick(self):
        key = self.ui.publicEdit.text()
        self.ui.encryptEdit.setText(key)


    def toPrivateButtonClick(self):
        key = self.ui.privateEdit.text()
        self.ui.decryptEdit.setText(key)


    def encryptButtonClick(self):
        publicKey = unicode(self.ui.encryptEdit.text())
        message = unicode(self.ui.leftEncryptTextEdit.toPlainText())
        encrypted = self.pycrypter.encrypt(publicKey, message.encode('utf-8'))
        self.ui.rightEncryptTextEdit.setPlainText(encrypted)


    def decryptButtonClick(self):
        privateKey = unicode(self.ui.decryptEdit.text())
        encrypted = unicode(self.ui.leftDecryptTextEdit.toPlainText())
        message = self.pycrypter.decrypt(privateKey, encrypted)
        self.ui.rightDecryptTextEdit.setPlainText(message.decode('utf-8'))


    def getlocalButtonClick(self):
        publicKey, privateKey = self._getLocalKeys()
        self.ui.publicEdit.setText(publicKey)
        self.ui.privateEdit.setText(privateKey)


    def updatelocalButtonClick(self):
        publicKey = unicode(self.ui.publicEdit.text())
        privateKey = unicode(self.ui.privateEdit.text())
        self._updateLocalKeys(publicKey, privateKey)


    def _getLocalKeys(self):
        if not os.path.exists(SETTINGS_PATH):
            os.mkdir(SETTINGS_PATH)

        publicPath = os.path.join(SETTINGS_PATH, "public.key")
        privatePath = os.path.join(SETTINGS_PATH, "private.key")

        if not os.path.exists(publicPath) or not os.path.exists(privatePath):
            keys = self.pycrypter.new()
            self._updateLocalKeys(keys['public'], keys['private'])

        with open(publicPath, 'rb') as f:
            publicKey = f.read()

        with open(privatePath, 'rb') as f:
            privateKey = f.read()

        return publicKey, privateKey


    def _updateLocalKeys(self, publicKey, privateKey):
        if not os.path.exists(SETTINGS_PATH):
            os.mkdir(SETTINGS_PATH)

        publicPath = os.path.join(SETTINGS_PATH, "public.key")
        privatePath = os.path.join(SETTINGS_PATH, "private.key")

        with open(publicPath, 'wb') as f:
            f.write(publicKey)

        with open(privatePath, 'wb') as f:
            f.write(privateKey)