53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
import asyncio
|
||
import websockets
|
||
import base64
|
||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||
from cryptography.hazmat.backends import default_backend
|
||
import json
|
||
|
||
# Конфигурация шифрования
|
||
KEY = b'8888888888888888'
|
||
IV_LENGTH = 16
|
||
|
||
async def test_client():
|
||
uri = "wss://ws.bitmex.com/realtime" # вместо этой строки будет строка с хостом и портом от сервера Дмитрия Андреевича
|
||
async with websockets.connect(uri) as websocket:
|
||
await websocket.send(json.dumps({"op": "subscribe", "args": ["trade"]})) # надеюсь жо этого не дойдет,
|
||
# но в идеале это не должно понадобиться так как у Дмитрия Андреевича только GET запрос (это POST)
|
||
while True:
|
||
resp = await websocket.recv()
|
||
print("Получено в зашифрованном виде:", resp)
|
||
|
||
asyncio.run(test_client())
|
||
#
|
||
# async def decrypt_message(encrypted_message):
|
||
# # Декодируем base64
|
||
# encrypted_data = base64.b64decode(encrypted_message)
|
||
#
|
||
# # Извлекаем IV и зашифрованный текст
|
||
# iv = encrypted_data[:IV_LENGTH]
|
||
# cipher_text = encrypted_data[IV_LENGTH:]
|
||
#
|
||
# # Создаем объект Cipher для расшифровки
|
||
# cipher = Cipher(algorithms.AES(KEY), modes.CBC(iv), backend=default_backend())
|
||
# decryptor = cipher.decryptor()
|
||
#
|
||
# # Расшифровываем данные
|
||
# decrypted_data = decryptor.update(cipher_text) + decryptor.finalize()
|
||
#
|
||
# # Удаляем PKCS5Padding
|
||
# padding_length = decrypted_data[-1]
|
||
# decrypted_data = decrypted_data[:-padding_length]
|
||
#
|
||
# return decrypted_data.decode('utf-8')
|
||
# async def listen():
|
||
# uri = "ws://45.67.56.214:8088/users"
|
||
# async with websockets.connect(uri) as websocket:
|
||
# while True:
|
||
# message = await websocket.recv()
|
||
# encrypted_messages = json.loads(message)
|
||
# for encrypted_message in encrypted_messages:
|
||
# decrypted_message = await decrypt_message(encrypted_message)
|
||
# print(decrypted_message)
|
||
#
|
||
# asyncio.get_event_loop().run_until_complete(listen()) |