Use MD5 hash for WebSocket connection keys

Replaces the plain concatenation of host, port, and path with an MD5 hash to generate unique keys for WebSocket connections. This improves key uniqueness and prevents potential issues with special characters in the key string.
This commit is contained in:
Namhyeon Go 2025-07-31 17:28:26 +09:00
parent 92a35606ed
commit f9c265b08a

View File

@ -7,6 +7,7 @@ using System;
using System.Collections.Concurrent;
using System.IO;
using System.Net.WebSockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -27,7 +28,13 @@ namespace WelsonJS.Launcher
private string MakeKey(string host, int port, string path)
{
return host + ":" + port + "/" + path;
// To create a unique key for the WebSocket connection
string input = host + ":" + port + "/" + path;
using (var md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
return BitConverter.ToString(hash).Replace("-", "").ToLower();
}
}
public async Task<ClientWebSocket> GetOrCreateAsync(string host, int port, string path)