/// <summary>
/// 避免代码中直接暴露字符串
/// 将字符串转字节
/// </summary>
/// <param name="byteDatas"></param>
/// <returns></returns>
public static string stringMakeBytesCode(this string txt)
{
var byteDatas = System.Text.Encoding.Unicode.GetBytes(txt);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < byteDatas.Length; i++)
{
builder.Append(string.Format("0x{0:X2} ", byteDatas[i]));
}
var res = builder.ToString();
//res = $"byte[] bts =new byte[{byteDatas.Length}] " + "{" + res.Replace(" ", ",") + "}";
res = $"var s = System.Text.Encoding.Unicode.GetString( new byte[{byteDatas.Length}] " + "{" + res.Replace(" ", ",") + "});";
return res;
}
c# 避免代码中直接暴露字符串
最新推荐文章于 2024-07-22 15:48:40 发布