diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 358d4e9a..c40e930d 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Principal; using System.Text; +using System.Text.RegularExpressions; using CliWrap; using CliWrap.Buffered; @@ -357,6 +358,14 @@ public class Utils return userHostsMap; } + public static List ParseCertSha256ToList(string certSha256Content) + { + return String2List(certSha256Content) + .Select(s => s.Replace(":", "").Replace(" ", "")) + .Where(s => s.Length == 64 && Regex.IsMatch(s, @"\A\b[0-9a-fA-F]+\b\Z")) + .ToList(); + } + #endregion 转换函数 #region 数据检查 diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index 8433d08b..a25cb72b 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -256,9 +256,7 @@ public partial class CoreConfigSingboxService if (node.CertSha256.IsNotEmpty()) { // hex to raw to base64 - var certSha256List = Utils.String2List(node.CertSha256) - .Select(s => s.Replace(":", "").Replace(" ", "")) - .Where(s => s.Length == 64 && Regex.IsMatch(s, @"\A[0-9a-fA-F]{64}\Z")) + var certSha256List = Utils.ParseCertSha256ToList(node.CertSha256) .Select(s => Convert.ToBase64String( Enumerable.Range(0, 32) .Select(i => Convert.ToByte(s.Substring(i * 2, 2), 16)) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index fcf5b8bd..1a28a71a 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -281,10 +281,7 @@ public partial class CoreConfigV2rayService } if (node.CertSha256.IsNotEmpty()) { - var certSha256List = Utils.String2List(node.CertSha256) - .Select(s => s.Replace(":", "").Replace(" ", "")) - .Where(s => s.Length == 64 && Regex.IsMatch(s, @"\A\b[0-9a-fA-F]+\b\Z")) - .ToList(); + var certSha256List = Utils.ParseCertSha256ToList(node.CertSha256); if (certSha256List.Count > 0) { tlsSettings.pinnedPeerCertificateSha256 = certSha256List;