def test_encryption(self): originalMessage = EncryptionHelper.padString("Hello") key = EncryptionHelper.generateKeyHash("world") iv = EncryptionHelper.generateIV() cipher = EncryptionHelper.encryptText(originalMessage, key, iv) self.assertNotEqual(originalMessage, cipher) message = EncryptionHelper.decryptCipher(cipher, key, iv) self.assertEqual(EncryptionHelper.stripPadding(message), EncryptionHelper.stripPadding(originalMessage))
def decryptFile(self, key, sameLocation = False): if sameLocation == False: outfile = open(self.getOriginalFileName(), "wb") else: outfileName = os.path.join(os.path.dirname(self.encryptedFileName), self.getOriginalFileName()) outfile = open(outfileName, "wb") # change the name of the encryptedFileName because right now it will be .exelocker file, change it to original extension data = self._handle.read(EncryptedFile._CHUNK_SIZE) cycle = 1 while data != "": message = EncryptionHelper.decryptCipher(data, key, self._iv) if cycle == self._cycles: message = EncryptionHelper.stripPadding(message) outfile.write(message) cycle = cycle + 1 data = self._handle.read(EncryptedFile._CHUNK_SIZE) outfile.close()
def decryptFile(self, key, sameLocation=False): if sameLocation == False: outfile = open(self.getOriginalFileName(), "wb") else: outfileName = os.path.join(os.path.dirname(self.encryptedFileName), self.getOriginalFileName()) outfile = open(outfileName, "wb") # change the name of the encryptedFileName because right now it will be .exelocker file, change it to original extension data = self._handle.read(EncryptedFile._CHUNK_SIZE) cycle = 1 while data != "": message = EncryptionHelper.decryptCipher(data, key, self._iv) if cycle == self._cycles: message = EncryptionHelper.stripPadding(message) outfile.write(message) cycle = cycle + 1 data = self._handle.read(EncryptedFile._CHUNK_SIZE) outfile.close()