From 655acb0bb466a373efe4c96c516bd6b55bda5b46 Mon Sep 17 00:00:00 2001 From: Elivo Date: Thu, 28 Aug 2025 12:07:09 +0800 Subject: [PATCH] =?UTF-8?q?Byte[]=20=E4=B8=8E=20HexString=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=EF=BC=8C=E5=8E=BB=E9=99=A4=E7=A9=BA=E6=A0=BC=E5=92=8C?= =?UTF-8?q?=E8=BF=9E=E5=AD=97=E7=AC=A6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/BytesUtility.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Apewer/BytesUtility.cs b/Apewer/BytesUtility.cs index eb31af8..0f983ce 100644 --- a/Apewer/BytesUtility.cs +++ b/Apewer/BytesUtility.cs @@ -165,7 +165,7 @@ namespace Apewer #region Text - /// 将字节数组转换为十六进制文本。 + /// 将字节数组转换为十六进制文本(小写)。 public static string ToHex(this byte[] bytes) { int length = bytes.Length; @@ -185,6 +185,9 @@ namespace Apewer /// 将十六进制文本转换为字节数组。 public static byte[] FromHex(this string hex) { + if (string.IsNullOrEmpty(hex)) return Empty; + hex = hex.Replace(" ", "").Replace("-", ""); + if (string.IsNullOrEmpty(hex) || hex.Length < 2) return Empty; if (hex.Length % 2 != 0) return Empty;