Я пытаюсь расшифровать голосовые данные, полученные от Discord, использующего режим шифрования xsalsa20_poly1305. Моя цель — записать и использовать аудио для общения с ИИ.
Что я могу сделать не так? Спасибо за любую помощь!
Мой код:
async def record_audio(udp_socket, ssrc, secret_key):
box = nacl.secret.SecretBox(bytes(secret_key)) # TODO: Fix decryption xsalsa20_poly1305
print("Listening for audio data...")
try:
response, _ = udp_socket.recvfrom(74)
print(f"Received response: {response}")
# Process the response...
except socket.timeout:
print("IP discovery timeout")
except Exception as e:
print(f"Unexpected error during IP discovery: {e}")
return None, None
while True:
print("Waiting for audio data...")
try:
ready, _, _ = select.select([udp_socket], [], [], 5.0)
if udp_socket in ready:
data, addr = udp_socket.recvfrom(65536) # Adjust buffer size as necessary
print(f"Received {len(data)} bytes from {addr}: {data.hex()}")
if len(data) > 12:
# Extract the RTP header
header = data[:12]
# Construct the nonce
nonce = header + b'\x00' * 12
print(f"Nonce: {len(nonce)} bytes")
# Get the encrypted audio data
encrypted = data[12:]
print(f"Encrypted audio data: {len(encrypted)} bytes")
#The rest of the data is the encrypted audio data (Should be 48 - 24 = 24 bytes)
#nonce = data[:12]
#print(f"Nonce: {nonce}")
#if len(nonce) < 12:
# nonce.ljust(24, b'\x00')
#remaining 12 bytes can be zeros or another fixed pattern
#nonce = nonce_part + bytes(12)
#copy the RTP header to get the nonce
#nonce = bytearray(24)
#nonce[:12] = data[:12]#data[:12]
#get the encrypted audio data
#encrypted = data[12:]
print(f"Encrypted audio data: {bytes(encrypted)}")
try:
audio_data = box.decrypt(bytes(data), bytes(nonce))
print("Received audio data")
except Exception as e:
print(f"Decryption error: {e}")
except Exception as e:
print(f"Error receiving audio data: {e}")
break
Изменить: секретный ключ передается непосредственно из объекта кода операции 4, полученного от Discord.
Вывод:
Waiting for audio data...
Received 48 bytes from ('66.22.243.22', 50023): 81c9000700013adfaf6439133ca81bfcd2b35eb743f2a4af0165e3cf0517d8efee5dae36ec6653c88a2d625064af33d6
Nonce: 24 bytes
Nonce: b'\x81\xc9\x00\x07\x00\x01:\xdf\xafd9\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Encrypted audio data: 36 bytes
Encrypted audio data: b'
Подробнее здесь: https://stackoverflow.com/questions/787 ... om-discord