From 4a41f768c204390b6048afbda56047b89388c68b Mon Sep 17 00:00:00 2001 From: shim_ <> Date: Thu, 19 Jul 2018 22:53:07 +0200 Subject: [PATCH] Python3 was a mistake --- imports/encryptedscreenshot.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/imports/encryptedscreenshot.py b/imports/encryptedscreenshot.py index 36080d5..3b883a2 100644 --- a/imports/encryptedscreenshot.py +++ b/imports/encryptedscreenshot.py @@ -5,7 +5,7 @@ from Crypto.Util import Counter from Crypto.PublicKey import RSA from Crypto.PublicKey import DSA from salsa20 import Salsa20_keystream -import os, struct, time, hashlib, hashlib, random +import os, struct, time, hashlib, hashlib, random, binascii class EncryptedScreenshot: @@ -15,7 +15,7 @@ class EncryptedScreenshot: random.choice("1234567890ABCDEFGHIJKLMNOPQRSTUWVXYZabcdefghijklmnopqrstuwvxyz") for _ in range(len)) self.password = rand(16) - print("Passphrase %s" % str(bytearray(self.passphrase())).encode("hex")) + print("Passphrase %s" % binascii.hexlify(self.passphrase())) self.id = id if id is None: self.id = rand(8) @@ -34,7 +34,7 @@ class EncryptedScreenshot: # new ScryptParameters(64, 8, 1,32, new Uint8List.fromList(new List())) print("Password units: %s" % (map(ord, self.password.encode("utf-8")),)) sha = hashlib.sha256() - sha.update(self.password) + sha.update(self.password.encode("utf-8")) return sha.digest() # scrypt.hash(self.password.encode("utf-8"), '', 64, 8, 1, 32) def assemble(self, file): @@ -51,8 +51,8 @@ class EncryptedScreenshot: encrypted_metadata = iv + str(bytearray(encrypted_metadata)) 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("%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(bson.loads(unencrypted_metadata)) @@ -73,8 +73,9 @@ class EncryptedScreenshot: def encryptor(self,length=0): iv = os.urandom(16) - ctr = Counter.new(128, initial_value=long(iv.encode("hex"), 16)) - print("IV: %s" % iv.encode("hex")) + nonce = int.from_bytes(binascii.hexlify(iv), byteorder='little') + ctr = Counter.new(128, nonce, 16) + print("IV: %s" % binascii.hexlify(iv)) cipher = AES.new(self.passphrase(), AES.MODE_CTR, counter=ctr) #salsa