diff --git a/imports/encryptedscreenshot.py b/imports/encryptedscreenshot.py index 3b883a2..ba655d9 100644 --- a/imports/encryptedscreenshot.py +++ b/imports/encryptedscreenshot.py @@ -42,20 +42,20 @@ class EncryptedScreenshot: self.metadata["hash"] = image_digest unencrypted_metadata = bson.dumps(self.metadata) if len(unencrypted_metadata) % 16 != 0: - unencrypted_metadata += ' ' * (16 - len(unencrypted_metadata) % 16) + unencrypted_metadata += b' ' * (16 - len(unencrypted_metadata) % 16) (encryptor, iv) = self.encryptor(len(unencrypted_metadata)) - encrypted_metadata = [] + encrypted_metadata = b'' encrypted_metadata += encryptor(unencrypted_metadata) - encrypted_metadata = iv + str(bytearray(encrypted_metadata)) + encrypted_metadata = iv + encrypted_metadata - print("Metadata: %s" % str(encrypted_metadata).encode("base64").replace("\n", "")) + #print("Metadata: %s" % str(encrypted_metadata).encode("base64").replace("\n", "")) #print("%s %s" % (str(encrypted_metadata[:16]).encode("hex"), str(encrypted_metadata[16:]).encode("hex"))) #print("Unencrypted: %s" % (unencrypted_metadata.encode("hex"))) - print("Password %s" % self.password) + #print("Password %s" % self.password) - print(bson.loads(unencrypted_metadata)) + #print(bson.loads(unencrypted_metadata)) fields = { "image": encrypted_image, @@ -73,8 +73,8 @@ class EncryptedScreenshot: def encryptor(self,length=0): iv = os.urandom(16) - nonce = int.from_bytes(binascii.hexlify(iv), byteorder='little') - ctr = Counter.new(128, nonce, 16) + nonce = int(binascii.hexlify(iv), 16) + ctr = Counter.new(128,initial_value = nonce)# initial_value = nonce) print("IV: %s" % binascii.hexlify(iv)) cipher = AES.new(self.passphrase(), AES.MODE_CTR, counter=ctr) @@ -95,7 +95,7 @@ class EncryptedScreenshot: def encrypt(self, file): filesize = os.path.getsize(file) (encryptor, iv) = self.encryptor(filesize) - binary = [] + binary = b'' digest = hashlib.sha256() with open(file, 'rb') as infile: # binary += struct.pack('