namespace NSExt.Extensions; public static class ByteExtensions { /// /// base64编码 /// /// 待编码的字节数组 /// 编码后的base64字符串 public static string Base64(this byte[] me) { return Convert.ToBase64String(me); } /// /// 将字节数组解码成字符串 /// /// 字节数组 /// 字符串使用的编码方式 /// 解码后的原始字符串 public static string HexDe(this byte[] me, Encoding e) { return e.GetString(me); } /// /// 将字节数组解码成字符串 /// /// 字节数组 /// 解码后的原始字符串 public static string HexDe(this byte[] me) { return me.HexDe(Encoding.UTF8); } /// /// 将字节数组转换成16进制字符串 /// /// /// 是否大写 /// 字节间分隔符 /// public static string String(this byte[] me, bool upperCase = true, string splitShar = null) { var ret = BitConverter.ToString(me); if (!upperCase) ret = ret.ToLower(); if (splitShar != "-") ret = ret.Replace("-", splitShar ?? string.Empty); return ret; } }