I know MAC is 4 first byte of last block encryption, and found this CMAC explanation here but it's kinda hard to understand. And maybe there are already some CMAC AES questions but I'm sorry I can't understand it well.
Anyone can explain how to calculate CMAC? and if necessary with some example code in C#. Thanks
First you need to derive two subkeys from your AES key. The algorithm is described well in RFC4493, but I will include some code samples here for reference. For this, you will need the AESEncrypt function, which you can write using dotNet AesCryptoServiceProvider:
And something to shift arrays left by one bit:
Now just the implementation of the algorithm in RFC4493 remains. I commented the logic from the RFC for easier understanding.
Good luck!