/// <summary> /// 加密数据 /// </summary> /// <param name="qiandaoNo"></param> /// <returns></returns> public static byte[] EncryptData(string msgType, string tpduStr, Dictionary <int, byte[]> data) { int signLength = 0; byte[] bcdMsgType = BCDUtil.str2Bcd(msgType); signLength += bcdMsgType.Length; string bin = ""; for (int i = 1; i <= 64; i++) { if (data.ContainsKey(i)) { bin += "1"; signLength += data[i].Length; } else { bin += "0"; } } byte[] bitMap = BCDUtil.str2Bcd(BCDUtil.leftpad(Convert.ToString(Convert.ToInt64(bin, 2), 16), 8)); signLength = signLength + bitMap.Length; signLength = signLength + 7; byte[] result = new byte[signLength]; int copytopos = 0; byte[] messageLen = BCDUtil.str2Bcd(BCDUtil.leftpad(Convert.ToString((signLength - 2), 16), 4)); byte[] tpdu = BCDUtil.str2Bcd(tpduStr); messageLen.CopyTo(result, copytopos); copytopos += 2; tpdu.CopyTo(result, copytopos); copytopos += 5; bcdMsgType.CopyTo(result, copytopos); copytopos += bcdMsgType.Length; bitMap.CopyTo(result, copytopos); copytopos += bitMap.Length; foreach (byte[] b in data.Values) { b.CopyTo(result, copytopos); copytopos += b.Length; } return(result); }
/// <summary> /// 计算MAC的加密数据 /// </summary> /// <param name="qiandaoNo"></param> /// <returns></returns> public static byte[] countMacData(string msgType, Dictionary <int, byte[]> data) { int signLength = 0; byte[] bcdMsgType = BCDUtil.str2Bcd(msgType); signLength += bcdMsgType.Length; string bin = ""; for (int i = 1; i <= 63; i++) { if (data.ContainsKey(i)) { bin += "1"; signLength += data[i].Length; } else { bin += "0"; } } bin += "1"; byte[] bitMap = BCDUtil.str2Bcd(BCDUtil.leftpad(Convert.ToString(Convert.ToInt64(bin, 2), 16), 8)); signLength = signLength + bitMap.Length; byte[] result = new byte[signLength]; int copytopos = 0; bcdMsgType.CopyTo(result, copytopos); copytopos += bcdMsgType.Length; bitMap.CopyTo(result, copytopos); copytopos += bitMap.Length; foreach (byte[] b in data.Values) { b.CopyTo(result, copytopos); copytopos += b.Length; } return(result); }