/// <summary> /// Method to check if the mic is valid /// </summary> /// <param name="nwskey">the network security key</param> /// <returns>if the Mic is valid or not</returns> public override bool CheckMic(string nwskey) { IMac mac = MacUtilities.GetMac("AESCMAC"); KeyParameter key = new KeyParameter(ConversionHelper.StringToByteArray(nwskey)); mac.Init(key); byte[] block = { 0x49, 0x00, 0x00, 0x00, 0x00, (byte)Direction, (byte)DevAddr.Span[3], (byte)DevAddr.Span[2], (byte)DevAddr.Span[1], (byte)DevAddr.Span[0], Fcnt.Span[0], Fcnt.Span[1], 0x00, 0x00, 0x00, (byte)(RawMessage.Length - 4) }; var algoinput = block.Concat(RawMessage.Take(RawMessage.Length - 4)).ToArray(); byte[] result = new byte[16]; mac.BlockUpdate(algoinput, 0, algoinput.Length); result = MacUtilities.DoFinal(mac); return(Mic.ToArray().SequenceEqual(result.Take(4).ToArray())); }