-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_loyal_code.py
More file actions
27 lines (19 loc) · 832 Bytes
/
decode_loyal_code.py
File metadata and controls
27 lines (19 loc) · 832 Bytes
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
import base64
from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import unpad,pad
import Cryptodome.Random
import os
def decrypt_from_base64(input_str, secret_key):
decoded_data = base64.b64decode(input_str)
iv = decoded_data[:16]
encrypted_data = decoded_data[16:]
cipher = AES.new(secret_key, AES.MODE_CBC, iv)
decrypted_data = unpad(cipher.decrypt(encrypted_data), AES.block_size)
return decrypted_data.decode('utf-8')
def encrypt_from_base64(input_str, secret_key):
decoded_data = base64.b64decode(input_str)
iv = Cryptodome.Random.get_random_bytes(16)
cipher = AES.new(secret_key, AES.MODE_CBC, iv)
encrypted_data = cipher.encrypt(pad(decoded_data, AES.block_size))
combined_data = iv + encrypted_data
return base64.b64encode(combined_data).decode('utf-8')