發(fā)布時間:2020-08-06 16:05 作者:獨孤劍 閱讀:3865
/// <summary> /// byte數組轉16進制字符串 /// </summary> /// <param name="data">byte數組</param> /// <returns></returns> public static string ByteArrayToHexString(byte[] data) { StringBuilder sb = new StringBuilder(data.Length * 3); foreach (byte b in data) { sb.Append(Convert.ToString(b, 16).PadLeft(2, '0')); } return sb.ToString().ToUpper(); } /// <summary> /// 16進制字符串轉byte數組 /// </summary> /// <param name="hexString">16進制字符</param> /// <returns></returns> public static byte[] ByteArrayToHexString(string hexString) { //將16進制秘鑰轉成字節(jié)數組 var byteArray = new byte[hexString.Length / 2]; for (var x = 0; x < byteArray.Length; x++) { var i = Convert.ToInt32(hexString.Substring(x * 2, 2), 16); byteArray[x] = (byte)i; } return byteArray; }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞