Exemple #1
0
 def generate(self):
     try:
         path = self.pathEdit.text()
         password = self.passEdit.text().encode()
         e = EncryptionHandler(id(password))
         salt = e.random(256)
         e.generateRSAKeys()
         iv = sha256(password + salt)[:16]
         e.generateAESObject(password, salt, iv, iterations=10000)
         priv = e.exportPrivateKey()
         self.dialog.rsa_key = priv
         priv = e.AESEncrypt(priv, 2400)
         if os.path.exists(path):
             os.remove(path)
         f = open(path, 'wb')
         f.write(priv + salt)
         f.close()
         msg = 'Successfully generated new keyfile!'
         self.dialog.addChatHistory(msg)
         self.logger.log(msg)
     except IOError as err:
         err_msg = "IO-Error: Couldn't save file."
         self.logger.log(err_msg, True)
         self.dialog.appendNormalMessage(err_msg)
     except BaseException as err:
         self.logger.log(str(err), True)
         self.dialog.appendNormalMessage(str(err))
     finally:
         self.close()
Exemple #2
0
 def load(self):
     path = self.pathEdit.text()
     try:
         e = EncryptionHandler()
         f = open(path, 'rb')
         data = f.read()
         f.close()
         password = self.passEdit.text().encode()
         priv, salt = split(data, 2400)
         iv = sha256(password + salt)[:16]
         e.generateAESObject(password, salt, iv, iterations=10000)
         priv = e.AESDecrypt(priv)
         self.dialog.rsa_key = priv
         msg = 'Successfully loaded keyfile!'
         self.dialog.addChatHistory(msg)
         self.logger.log(msg)
     except VerificationError as err:
         err_msg = 'Error decrypting the file: ' + str(err) + ' (Wrong password?)'
         self.logger.log(err_msg, True)
         self.dialog.appendNormalMessage(err_msg)
         self.dialog.rsa_key = None
     except IOError as err:
         err_msg = "IO-Error: Couldn't open file."
         self.logger.log(err_msg, True)
         self.dialog.appendNormalMessage(err_msg)
     except BaseException as err:
         self.logger.log(str(err), True)
         self.dialog.appendNormalMessage(str(err))
     finally:
         self.close()