コード例 #1
0
    def checkInfo(self):
        '''Checks that all the information fields are filled out and valid.  Loads the required information and passes it for encrypted image creation.'''
        common.turnBlack(self.missingInfo)
        self.missingInfo = []

        # Checks that a public key image has been selected and the relevant information has been filled in.
        if self.pkSelectGroup.checkedId() == -1:
            self.missingInfo.append(self.pkLabel)
        elif self.pkSelectGroup.checkedId() == 1 and self.pkFromHDText.text() == '':
            self.missingInfo.append(self.pkFromHD)
        elif self.pkSelectGroup.checkedId() == 2 and self.pkFromInternetText.text() == '':
            self.missingInfo.append(self.pkFromInternet)

        # Checks that a encrypted image has been selected and the relevant information has been filled in.
        if self.encSelectGroup.checkedId() == -1:
            self.missingInfo.append(self.encLabel)
        elif self.encSelectGroup.checkedId() == 1 and self.encFromHDText.text() == '':
            self.missingInfo.append(self.encFromHD)
        elif self.encSelectGroup.checkedId() == 2 and self.encFromInternetText.text() == '':
            self.missingInfo.append(self.encFromInternet)

        # Checks that message method has been selected and the relevant information has been filled in.
        if self.msgSelectGroup.checkedId() == -1:
            self.missingInfo.append(self.msgLabel)
        elif self.msgSelectGroup.checkedId() == 1 and self.msgFromHDText.text() == '':
            self.missingInfo.append(self.msgFromHD)
        elif self.msgSelectGroup.checkedId() == 2 and self.msgInputText.toPlainText() == '':
            self.missingInfo.append(self.msgInput)

        # Turns missing information labels red, or attempts to load the images if we have no missing information.
        if self.missingInfo != []:
            common.turnRed(self.missingInfo)
            common.popUpText(self, 'Error: Missing information.  Empty fields have been highlighted.', 'Error')
        else:
            self.pkImageLoad()
コード例 #2
0
    def pkInformation(self):
        '''Extracts public key information from the public key image'''
        # Extract the information.
        self.curve_name, self.B = imageops.ExtractImageInfo(self.pkImage, 'public key')

        # Check that the information is valid.
        if type(self.B) == str:
            common.popUpText(self, self.B, 'Error')
        else:
            self.encBaseImageLoad()
コード例 #3
0
 def decryptImg(self):
     '''Extracts, decrypts, and displays the hidden message.'''
     # Message to display while decryption is in process.
     self.msgText.setText('Decrypting your message...')
     self.msgText.repaint()
     self.curve_name, self.decryptList = imageops.ExtractImageInfo(self.encImage, 'encrypted message')
     if type(self.decryptList) == str:
         self.msgText.setText('')
         self.msgText.repaint()
         common.popUpText(self, self.decryptList, 'Error')
     else:
         self.concealedMsg = decrypt.DecryptECIES(self.curve_name, self.decryptList[0], self.decryptList[1], self.decryptList[2], self.passwordText.text())
         self.msgText.setText(self.concealedMsg)
コード例 #4
0
    def encImageLoad(self):
        '''Loads the encrypted image'''
        # Load from Hard Drive
        if self.encSelectGroup.checkedId() == 1:
            try:
                self.encImage = Image.open(self.encFromHDText.text())
                self.decryptImg()
            except IOError:
                common.popUpText(self, 'Error: Cannot open encrypted image.  Please try another image.', 'Error')
        # Load from Internet
        elif self.encSelectGroup.checkedId() == 2:
            try:
                self.urlEncImage = cStringIO.StringIO(urllib.urlopen(self.encFromInternetText.text()).read())
                self.encImage = Image.open(self.urlEncImage)
                self.decryptImg()

            except IOError:
                common.popUpText(self, 'Error: Cannot open encrypted image.  Please verify that the website address is correct or try another image.', 'Error')
コード例 #5
0
 def pkImageLoad(self):
     '''Loads the public key image '''
     # Public Key Image from Hard Drive
     if self.pkSelectGroup.checkedId() == 1:
         try:
             self.pkImage = Image.open(self.pkFromHDText.text())
             self.pkInformation()
         except IOError:
             self.missingInfo.append(self.pkFromHD)
             common.turnRed(self.missingInfo)
             common.popUpText(self, 'Error: Cannot open public key image. Please try another image.', 'Error')
     # Public Key Image from Internet
     elif self.pkSelectGroup.checkedId() == 2:
         try:
             self.urlPKImage = cStringIO.StringIO(urllib.urlopen(self.pkFromInternetText.text()).read())
             self.pkImage = Image.open(self.urlPKImage)
             self.pkInformation()
         except IOError:
             self.missingInfo.append(self.pkFromInternet)
             common.turnRed(self.missingInfo)
             common.popUpText(self, 'Error: Cannot open public key image.  Please verify that the website address is correct or try another image.', 'Error')
コード例 #6
0
 def setHiddenMsg(self):
     '''Loads the message to encrypted and conceal.'''
     # Message from txt file
     if self.msgSelectGroup.checkedId() == 1:
         try:
             msgFile = open(self.msgFromHDText.text())
             self.hiddenMsg = msgFile.read()
             msgFile.close()
             self.createEncImg()
         except IOError:
             self.missingInfo.append(self.msgFromHD)
             common.turnRed(self.missingInfo)
             common.popUpText(self, 'Error: Cannot get a message from the text file.  Please select another text file.', 'Error')
         except:
             self.missingInfo.append(self.msgFromHD)
             common.turnRed(self.missingInfo)
             common.popUpText(self, 'Error: Cannot get a message from the text file.  Please select another text file.', 'Error')
             raise
     # Message from GUI textbox
     elif self.msgSelectGroup.checkedId() == 2:
         self.hiddenMsg = self.msgInputText.toPlainText()
         self.createEncImg()
コード例 #7
0
    def encBaseImageLoad(self):
        '''Loads the public key image '''
        # Image from Hard Drive
        if self.encSelectGroup.checkedId() == 1:
            try:
                self.encBaseImage = Image.open(self.encFromHDText.text())
                self.setHiddenMsg()
            except IOError:
                self.missingInfo.append(self.encFromHD)
                common.turnRed(self.missingInfo)
                common.popUpText(self, 'Error: Cannot open encrypted image.  Please try another image.', 'Error')
        # Image from the Internet
        elif self.encSelectGroup.checkedId() == 2:
            try:
                self.urlEncImage = cStringIO.StringIO(urllib.urlopen(self.encFromInternetText.text()).read())
                self.encBaseImage = Image.open(self.urlEncImage)
                self.setHiddenMsg()

            except IOError:
                self.missingInfo.append(self.encFromInternet)
                common.turnRed(self.missingInfo)
                common.popUpText(self, 'Error: Cannot open encrypted image.  Please verify that the website address is correct or try another image.', 'Error')
コード例 #8
0
    def checkInfo(self):
        '''Checks that all the information fields are filled out and valid.  Loads the required information and passes it for encrypted image creation.'''
        common.turnBlack(self.missingInfo)
        self.missingInfo = []

        # Checks that an encrypted image is selected and relevant information is present.
        if self.encSelectGroup.checkedId() == -1:
            self.missingInfo.append(self.encLabel)
        elif self.encSelectGroup.checkedId() == 1 and self.encFromHDText.text() == '':
            self.missingInfo.append(self.encFromHD)
        elif self.encSelectGroup.checkedId() == 2 and self.encFromInternetText.text() == '':
            self.missingInfo.append(self.encFromInternet)

        # Checks that a password has been entered.
        if self.passwordText.text() == '':
            self.missingInfo.append(self.inputPasswordLabel)
            self.missingInfo.append(self.passwordLabel)

        # Turns missing information labels red, or attempts to load the images if we have no missing information.
        if self.missingInfo != []:
            common.turnRed(self.missingInfo)
            common.popUpText(self, 'Error: Missing information.  Empty fields have been highlighted.', 'Error')
        else:
            self.encImageLoad()
コード例 #9
0
    def checkInfo(self):
        '''Checks that all the information fields are filled out.  Creates the public key image once information is complete.'''
        common.turnBlack(self.missingInfo)
        self.missingInfo = []

        # Check that a curve has been selected.
        if self.curveGroup.checkedId() == -1:
            self.missingInfo.append(self.curveLabel)

        # Check that an image location has been selected and location information is present.
        if self.selectGroup.checkedId() == -1:
            self.missingInfo.append(self.selectImageLabel)
        elif self.selectGroup.checkedId() == 1 and self.fromHDText.text() == '':
            self.missingInfo.append(self.fromHD)
        elif self.selectGroup.checkedId() == 2 and self.fromInternetText.text() == '':
            self.missingInfo.append(self.fromInternet)

        # Check that a password is filled in and that the two password fields match.
        if self.passwordText.text() == '':
            self.missingInfo.append(self.createPasswordLabel)
        elif self.passwordText.text() != self.cPasswordText.text():
            self.missingInfo.append(self.passwordLabel)
            self.missingInfo.append(self.cPasswordLabel)

        # Turns missing information labels red, or attempts to load the image if we have no missing information.
        if self.missingInfo != []:
            common.turnRed(self.missingInfo)
            common.popUpText(self, 'Error: Missing information.  Empty fields have been highlighted.', 'Error')

        else:
            if self.selectGroup.checkedId() == 1:
                try:
                    self.baseImage = Image.open(self.fromHDText.text())
                    self.createPK()

                except IOError:
                    self.missingInfo.append(self.fromHD)
                    common.turnRed(self.missingInfo)
                    common.popUpText(self,'Error: Cannot open image.  Please try another image.', 'Error')

            elif self.selectGroup.checkedId() == 2:
                try:
                    self.urlImage = cStringIO.StringIO(urllib.urlopen(self.fromInternetText.text()).read())
                    self.baseImage = Image.open(self.urlImage)
                    self.createPK()

                except IOError:
                    self.missingInfo.append(self.fromInternet)
                    common.turnRed(self.missingInfo)
                    common.popUpText(self,'Error: Cannot open image.  Please verify that the website address is correct or try another image.', 'Error')
コード例 #10
0
    def saveMessage(self):
        '''Saves the message as a .txt file'''
        if self.msgText.toPlainText() != '':
            saveLocation, _ = QtGui.QFileDialog.getSaveFileName(self, 'Save Message', 'msg', 'Text Files (*.txt)')

            if saveLocation != '':
                try:
                    savedTxtFile = open(saveLocation, 'w')
                    savedTxtFile.write(self.concealedMsg)
                    savedTxtFile.close()
                    common.popUpText(self, 'Message successfully saved!', 'Success')
                except:
                    common.popUpText(self, 'Error: Failed to save the message.  Something has gone very wrong.', 'Error')
                    raise
        else:
            common.popUpText(self, 'Error: No message to save.', 'Error')
コード例 #11
0
    def createEncImg(self):
        '''Creates and saves the public key image'''
        # Create the encrypted image.
        self.encImage = encrypt.EncryptECIES(self.curve_name, self.B, self.hiddenMsg, self.encBaseImage)

        # Checks if the image was created correctly and, if so, saves it.
        if type(self.encImage) == str:
            common.popUpText(self, self.encImage, 'Error')

        else:
            saveLocation, _ = QtGui.QFileDialog.getSaveFileName(self, 'Save Encrypted Image', 'encrypted', '.png Files (*.png)')

            if saveLocation != '':
                try:
                    self.encImage.save(saveLocation, 'PNG', quality=95)
                    common.popUpText(self, 'Encrypted Image Successfully Created!', 'Success')

                except:
                    common.popUpText(self, 'Error: Failed to save image.  Something has gone very wrong.', 'Error')
                    raise
コード例 #12
0
    def createPK(self):
        '''Creates and saves the public key image'''
        # Create the public key image.
        publicKeyImage = PublicKeyECIES(self.curveGroup.checkedButton().text(), self.passwordText.text(), self.baseImage)

        # Checks if the image was created correctly and, if so, saves it.
        if type(publicKeyImage) == str:
            common.popUpText(self, publicKeyImage, 'Error')

        else:
            saveLocation, _ = QtGui.QFileDialog.getSaveFileName(self, 'Save Public Key Image', 'public_key', '.png Files (*.png)')

            if saveLocation != '':
                try:
                    publicKeyImage.save(saveLocation, 'PNG', quality=95)
                    common.popUpText(self, 'Public Key Image Successfully Created!', 'Success')

                except:
                    common.popUpText(self,'Error: Failed to save image.  Something has gone very wrong.','Error')
                    raise