From 629f12a9b76ac69d565ae30359d3c8d9133be8bf Mon Sep 17 00:00:00 2001 From: hs_junxiang Date: Thu, 21 Sep 2023 15:20:43 +0800 Subject: [PATCH] Update --- pyga4/analytic/data_transform.py | 37 -------------------------------- 1 file changed, 37 deletions(-) diff --git a/pyga4/analytic/data_transform.py b/pyga4/analytic/data_transform.py index 09e3749..de0ddcd 100644 --- a/pyga4/analytic/data_transform.py +++ b/pyga4/analytic/data_transform.py @@ -1,47 +1,10 @@ import base64 -import json from datetime import datetime, timedelta, timezone from typing import Union, Iterable -from Crypto.Cipher import AES -from Crypto.Util.Padding import unpad - class Transformer: """Transform the data of GA4""" - - @staticmethod - def decryptData( - encoded_data: Union[str, Iterable], - key = b'secret_key' - ) -> Union[str, list]: - """ Decrypt Data (string or json) - """ - if isinstance(encoded_data, str): - # 將 base64 編碼的數據解碼並進行解密 - encrypted_data = base64.b64decode(encoded_data) - - # 進行 Zero Padding - key = key.ljust(16, b'\x00') - - # 創建 AES 解密器 - cipher = AES.new(key, AES.MODE_CBC, key) - - decrypted_data = unpad(cipher.decrypt(encrypted_data), AES.block_size) - - try: - json_data = decrypted_data.decode() - data = json.loads(json_data) - except (json.JSONDecodeError, UnicodeDecodeError): - data = decrypted_data.decode() - - return data - - decrypted_list = [] - for item in encoded_data: - decrypted_list.append(Transformer.decryptData(item, key)) - return decrypted_list - @staticmethod def timestamp_to_datetime( ga4_timestamp: Union[str, Iterable]