Exemplo n.º 1
0
 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))
Exemplo n.º 2
0
 def __init__(self, encryptedFileName):
     if os.path.exists(encryptedFileName) and EncryptedFile.isValidFile(encryptedFileName):
         self.encryptedFileName = encryptedFileName
         self._handle = open(encryptedFileName, "rb")
         self._handle.read(10) # skip reading magic number
         self._checksum = self._handle.read(32) # read 32 bytes checksum from file
         self._filename = EncryptionHelper.stripPadding(self._handle.read(255)) # read filename
         # and then strip padding
         self._iv = self._handle.read(16) # read 16 bytes IV
         self._cycles = (os.stat(encryptedFileName).st_size) / (64 * 1024) # divided by 64kbytes
     else:
         raise Exception("File does not exist or not a valid EXELocker File.")
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 def __init__(self, encryptedFileName):
     if os.path.exists(encryptedFileName) and EncryptedFile.isValidFile(
             encryptedFileName):
         self.encryptedFileName = encryptedFileName
         self._handle = open(encryptedFileName, "rb")
         self._handle.read(10)  # skip reading magic number
         self._checksum = self._handle.read(
             32)  # read 32 bytes checksum from file
         self._filename = EncryptionHelper.stripPadding(
             self._handle.read(255))  # read filename
         # and then strip padding
         self._iv = self._handle.read(16)  # read 16 bytes IV
         self._cycles = (os.stat(encryptedFileName).st_size) / (
             64 * 1024)  # divided by 64kbytes
     else:
         raise Exception(
             "File does not exist or not a valid EXELocker File.")
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
 def test_stripPadding(self):
     originalString = "hello"
     paddedString = EncryptionHelper.padString("hello")
     self.assertNotEqual(originalString, paddedString)
     self.assertEquals(originalString, EncryptionHelper.stripPadding(paddedString))