Need to generate 35 bytes (70 characters) Alphanumerical data using ISO 9797-1 MAC algorithm 3 and padding method 1 in java.
I have tried using below code but its not generating 35 bytes (70 characters) Alphanumerical data and using key as 64 byte key.
public byte[] getRetailMAC(byte[] key, byte[] data) {
int macSizeBits = 64;
BlockCipher cipher = new DESEngine();
Mac mac = new ISO9797Alg3Mac(cipher, macSizeBits);
KeyParameter keyP = new KeyParameter(key);
mac.init(keyP);
mac.update(data, 0, data.length);
// perform padding manually
int n = cipher.getBlockSize();
int zeroPaddingRequired = n - (data.length + n - 1) % n - 1;
for (int i = 0; i < zeroPaddingRequired; i++) {
mac.update((byte) 0x00);
}
byte[] out = new byte[macSizeBits / Byte.SIZE];
mac.doFinal(out, 0);
return out;
}
and I expect the output is 35 bytes (70 characters) Alphanumerical data
but actual output getting above code is :[B@2ee0d183
.
Can anyone please help me on this.