I am trying to integrate org.bouncycastle.crypto.macs.ISO9797Alg3Mac
on my application. while calling the method, I am getting below error,
java.lang.IllegalArgumentException: Key must be either 112 or 168 bit long at
org.bouncycastle.crypto.macs.ISO9797Alg3Mac.init(Unknown Source:119)
Here is the method I am using to generate Mac,
fun getISO9797Alg3Mac(key: ByteArray?, data: ByteArray): ByteArray {
//To print the MacKey
"MacKey : ${macKey} ,ByteArray Size: ${macKey.length}".toLog()
val macSizeBits = 32
val cipher: BlockCipher = DESEngine()
val mac = ISO9797Alg3Mac(cipher)
val keyP = KeyParameter(key)
mac.init(keyP)
mac.update(data, 0, data.size)
val out = ByteArray(macSizeBits / java.lang.Byte.SIZE)
mac.doFinal(out, 0)
return out
}
My Mackey is like this,
MacKey : 00000000-6b4b-282b-0000-00006b4b282b24.783063446.7061012
ByteArray Size : 56