mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
V2Ray : Support Xray UUIDv5 mapping standard
This commit is contained in:
@@ -82,7 +82,7 @@ public static class V2rayConfigUtils
|
||||
{
|
||||
new User
|
||||
{
|
||||
id = vless.UserID,
|
||||
id = getUUID(vless.UserID),
|
||||
flow = vless.Flow.ValueOrDefault(),
|
||||
encryption = vless.EncryptMethod
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public static class V2rayConfigUtils
|
||||
{
|
||||
new User
|
||||
{
|
||||
id = vmess.UserID,
|
||||
id = getUUID(vmess.UserID),
|
||||
alterId = vmess.AlterID,
|
||||
security = vmess.EncryptMethod
|
||||
}
|
||||
@@ -366,4 +366,13 @@ public static class V2rayConfigUtils
|
||||
|
||||
return streamSettings;
|
||||
}
|
||||
|
||||
public static string getUUID(string uuid)
|
||||
{
|
||||
if (uuid.Length == 36 || uuid.Length == 32)
|
||||
{
|
||||
return uuid;
|
||||
}
|
||||
return uuid.GenerateUUIDv5();
|
||||
}
|
||||
}
|
||||
@@ -78,4 +78,30 @@ public static class StringExtension
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(value) ? value.Split(',') : default;
|
||||
}
|
||||
|
||||
public static string GenerateUUIDv5(this string str)
|
||||
{
|
||||
// https://github.com/XTLS/Xray-core/discussions/715
|
||||
// https://xray-uuid.ducksoft.site/
|
||||
|
||||
SHA1 sha1 = new SHA1CryptoServiceProvider();
|
||||
|
||||
// example string: "example"
|
||||
List<byte> byteSource = new List<byte>();
|
||||
byteSource.AddRange(new byte[16]);
|
||||
byteSource.AddRange(Encoding.UTF8.GetBytes(str));
|
||||
|
||||
byte[] Sha1Bytes = sha1.ComputeHash(byteSource.ToArray()).Skip(0).Take(16).ToArray();
|
||||
sha1.Dispose();
|
||||
|
||||
//UUIDv5: [254 181 68 49 48 27 82 187 166 221 225 233 62 129 187 158]
|
||||
|
||||
Sha1Bytes[6] = (byte)((Sha1Bytes[6] & 0x0f) | (5 << 4));
|
||||
Sha1Bytes[8] = (byte)(Sha1Bytes[8] & (0xff >> 2) | (0x02 << 6));
|
||||
|
||||
return BitConverter.ToString(Sha1Bytes).Replace("-", "")
|
||||
.Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-")
|
||||
.ToLower();
|
||||
//UUIDv5: feb54431-301b-52bb-a6dd-e1e93e81bb9e
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user