字符串转字节数组
var str = "hello world"; byte[] byteArray = System. Text. Encoding. UTF8. GetBytes(str);
字节数组转字符串
byte[] byteArray; string str = System.Text.Encoding.UTF8.GetString(byteArray);
字节数组转十六进制字符串
/// <summary> /// 字节数组转十六进制字符串 /// </summary> /// <param name="bytes"></param> /// <param name="connector"></param> /// <returns></returns> public static string BytesToHexStr(byte[] bytes, string connector = "") { string returnStr = ""; if (bytes != null) { for (int i = 0; i < bytes.Length; i++) { returnStr += (bytes[i].ToString("X2") + connector); } } return returnStr; }