mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-21 20:50:40 -05:00
Add server version to master api
Add IsEvadedOffense to EFPenalty Fix remote log reading in not Windows
This commit is contained in:
@ -0,0 +1,35 @@
|
||||
import pickle
|
||||
from Crypto.Cipher import AES
|
||||
from base64 import b64encode, b64decode
|
||||
|
||||
|
||||
__all__ = "encrypt", "decrypt"
|
||||
|
||||
BLOCK_SIZE = 16
|
||||
INTERRUPT = b'\0' # something impossible to put in a string
|
||||
PADDING = b'\1'
|
||||
|
||||
|
||||
def pad(data):
|
||||
return data + INTERRUPT + PADDING * (BLOCK_SIZE - (len(data) + 1) % BLOCK_SIZE)
|
||||
|
||||
|
||||
def strip(data):
|
||||
return data.rstrip(PADDING).rstrip(INTERRUPT)
|
||||
|
||||
|
||||
def create_cipher(key, seed):
|
||||
if len(seed) != 16:
|
||||
raise ValueError("Choose a seed of 16 bytes")
|
||||
if len(key) != 32:
|
||||
raise ValueError("Choose a key of 32 bytes")
|
||||
return AES.new(key, AES.MODE_CBC, seed)
|
||||
|
||||
|
||||
def encrypt(plaintext_data, key, seed):
|
||||
plaintext_data = pickle.dumps(plaintext_data, pickle.HIGHEST_PROTOCOL) # whatever you give me I need to be able to restitute it
|
||||
return b64encode(create_cipher(key, seed).encrypt(pad(plaintext_data)))
|
||||
|
||||
|
||||
def decrypt(encrypted_data, key, seed):
|
||||
return pickle.loads(strip(create_cipher(key, seed).decrypt(b64decode(encrypted_data))))
|
Reference in New Issue
Block a user