コード例 #1
0
        public override byte[] GetByteMessage()
        {
            List <byte> messageArray = new List <byte>();

            messageArray.AddRange(Mhdr.ToArray());
            messageArray.AddRange(AppEUI.ToArray());
            messageArray.AddRange(DevEUI.ToArray());
            messageArray.AddRange(DevNonce.ToArray());
            if (!Mic.Span.IsEmpty)
            {
                messageArray.AddRange(Mic.ToArray());
            }
            return(messageArray.ToArray());
        }
コード例 #2
0
        private byte[] PerformMic(string appKey)
        {
            IMac mac = MacUtilities.GetMac("AESCMAC");

            KeyParameter key = new KeyParameter(ConversionHelper.StringToByteArray(appKey));

            mac.Init(key);

            var algoinput = Mhdr.ToArray().Concat(AppEUI.ToArray()).Concat(DevEUI.ToArray()).Concat(DevNonce.ToArray()).ToArray();

            byte[] result = new byte[19];
            mac.BlockUpdate(algoinput, 0, algoinput.Length);
            result = MacUtilities.DoFinal(mac);
            var resStr = BitConverter.ToString(result);

            return(result.Take(4).ToArray());
        }