Hi everyone !
I have a C++ source code that uses AES with CBC mode to create MACs. I would like to do the same in Java (no special padding as it is manually padded with zero bytes), but I can't make it work after hours :-(
I've tried using BoucyCastle libraries with this kind of code :
(key is a 16-length byte array, and msg is a byte array padded with zeros (length is multiple of 16 bytes))
BlockCipher cipher = new AESLightEngine();
CBCBlockCipherMac mac = new CBCBlockCipherMac(cipher);
// use the key to create cipherparameters
KeyParameter keyparam = new KeyParameter(key);
// init cipher
mac.init(keyparam);
byte[] result = new byte[mac.getMacSize() + 8];
// read bytes into buffer and feed these bytes into Hmac object
mac.update(msg, 0, length);
mac.doFinal(result, mac.getMacSize());
return result;
but it does not return the MAC that my C++ code returns (with the same pair of msg/key). Note : The MAC the c++ returns is OK (I'm sure of it).
Could someone help me ?
Thx a lot in advance.