· 6 years ago · Jan 21, 2020, 02:18 AM
1def encryptReg(keyID,pubkey,password,time):
2
3 # function(s, c, h, l)
4 # s = keyID or keyVersion, c = public key, h = password, l = time?
5
6 # Modeled After
7 def parsePkey(key): # function n(t) {
8 n = [] # const n = [];
9 for o in range(0,len(key),2): # for (let o = 0; o < t.length; o += 2)
10 n.append(int(key[o:o+2],16)) # n.push(parseInt(t.slice(o, o + 2), 16));
11 return n # return new Uint8Array(n)
12
13
14 def js_set(list1,arr,pos):
15 list1[pos:pos+len(arr)] = arr
16
17
18
19 o = 100 # idk
20 u = o + len(password) # Always o + password length
21
22 if 64 != len(pubkey): # Public Key is always 64 chars
23 print("Invalid Public Key")
24
25 pubkey = parsePkey(pubkey)
26
27 y = bytearray(u) # Creating Byte Array Length of 100 + length of password
28 f = 0
29 y[f] = 1
30 f = 1
31 y[f] = int(keyID) # Sets 2nd byte to keyID
32 f = 2 # Parsed Pubkey and Array y match with Javascript at this point
33
34 key = get_random_bytes(32) # = subtle.generateKey 256 bits
35 iv = get_random_bytes(12) #
36 tag_length = 16
37
38 aesCypher = AES.new(key, AES.MODE_GCM,mac_len=tag_length)
39
40
41 cipherText,cipherTag = aesCypher.encrypt_and_digest(bytearray(password,'utf-8'))
42
43 cipherText = cipherText + cipherTag # Turns out web crypto api outputs the tag with it - 1 hour wasted
44 # stuff relating to tweetnacl.sealedbox.seal(new Uint8Array(ckey), pkey)
45
46 #print(len(bytes(pubkey)))
47 pubkeySeal = PublicKey(bytes(pubkey))
48 privkeySeal = PrivateKey(bytes(key))
49
50 sealed = SealedBox(pubkeySeal)
51
52 final_sealed = sealed.encrypt(bytes(key)) # length 80
53
54
55 y[2] = 80 # sealed.length >> 8 & 255,
56
57 js_set(y,final_sealed,4)
58
59
60 f = 84
61
62 s = numpy.frombuffer(cipherText,dtype=numpy.uint8)
63 c = s[-len(password):]
64 h = s[0:len(password)]
65
66 y[84] = c[0]
67 y[85] = c[1]
68
69 f = 100
70 y[100] = h[0]
71 y[101] = h[1]
72 #print(s)
73 #print(c)
74 #print(h)
75
76 final_enc = str(b64encode(y).decode('utf-8'))
77 app = 6
78 return "#PWD_INSTAGRAM_BROWSER"+':'+str(app)+':'+time+':'+final_enc
79
80print(encryptReg('245',"f5a1fdb4e2e032e5d3b42c3350d69918eebdb640e2f9cc0fe1fc55cd7800cf30",'21',str(int((datetime.datetime.now().timestamp()*1000)))))