-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmanagerCrypto.py
More file actions
69 lines (51 loc) · 2.22 KB
/
Copy pathXmanagerCrypto.py
File metadata and controls
69 lines (51 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import win32api
import win32security
import base64
from Crypto.Hash import MD5, SHA256
from Crypto.Cipher import ARC4
class XmanagerCrypto:
def __init__(self):
self.Key = b'!X@s# h$e%l^l&'
def EncryptString(self, s):
Cipher = ARC4.new(MD5.new(self.Key).digest())
return base64.b64encode(Cipher.encrypt(s.encode())).decode()
def DecryptString(self, s):
Cipher = ARC4.new(MD5.new(self.Key).digest())
return Cipher.decrypt(base64.b64decode(s)).decode()
class Xmanager5Crypto:
def __init__(self, username = '', usersid = ''):
if username == '' and usersid == '':
self.UserName = win32api.GetUserName()
CurrentUserSID = win32security.LookupAccountName(win32api.GetComputerName(), self.UserName)[0]
self.UserSID = win32security.ConvertSidToStringSid(CurrentUserSID)
else:
self.UserName = str(username)
self.UserSID = str(usersid)
def EncryptString(self, s):
Cipher = ARC4.new(SHA256.new(self.UserSID.encode()).digest())
Plaintext = s.encode()
Checksum = SHA256.new(Plaintext).digest()
Ciphertext = Cipher.encrypt(Plaintext)
return base64.b64encode(Ciphertext + Checksum).decode()
def DecryptString(self, s):
Cipher = ARC4.new(SHA256.new(self.UserSID.encode()).digest())
Data = base64.b64decode(s)
Checksum = Data[-32:]
Ciphertext = Data[0:-32]
Plaintext = Cipher.decrypt(Ciphertext)
assert SHA256.new(Plaintext).digest() == Checksum
return Plaintext.decode()
def EncryptString2(self, s):
Cipher = ARC4.new(SHA256.new((self.UserName + self.UserSID).encode()).digest())
Plaintext = s.encode()
Checksum = SHA256.new(Plaintext).digest()
Ciphertext = Cipher.encrypt(Plaintext)
return base64.b64encode(Ciphertext + Checksum).decode()
def DecryptString2(self, s):
Cipher = ARC4.new(SHA256.new((self.UserName + self.UserSID).encode()).digest())
Data = base64.b64decode(s)
Checksum = Data[-32:]
Ciphertext = Data[0:-32]
Plaintext = Cipher.decrypt(Ciphertext)
assert SHA256.new(Plaintext).digest() == Checksum
return Plaintext.decode()