/// <summary> /// /// </summary> /// <param name="joinAcceptMessage"></param> /// <param name="appKey"></param> public CalculatedMIC(JoinRequestMessage joinRequestMessage, byte[] appKey) { if (appKey != null && appKey.Length == 16) { CryptoService crypto = new CryptoService(); // cmac = aes128_cmac(AppKey, MHDR | AppEUI | DevEUI | DevNonce) // MIC = cmac[0..3] byte[] data = new byte[joinRequestMessage.RawData.Length + 1]; joinRequestMessage.Parent.Mhdr.RawData.CopyTo(data.AsSpan()); // [1] joinRequestMessage.RawData.CopyTo(data.AsSpan(1)); byte[] fullCAMC = crypto.AESCMAC(appKey, data); RawData = fullCAMC.AsSpan(0, 4).ToArray(); IsValid = true; } else { RawData = Array.Empty <byte>(); IsValid = false; } }