Search code examples
javaencryptioncryptographyhmac3des

looking for a way to calculate Mac using the ISO 9797-1 Algorithm 3(Retail MAC)


Looking through Java Cryptography Architecture and code examples, I have learned how to calculate the Mac using Mac class:

Mac mac = Mac.getInstance("HmacMD5");
mac.init(<secretKeyHere>);
byte[] macHash = mac.doFinal(<encryptedTextHere>); 

But I am actually looking for a way to calculate Mac using the ISO 9797-1 Algorithm 3(Retail MAC).

Can someone suggest me a code example in Java?


Solution

  • It is not available in any of the Oracle providers, however if you add the Bouncycastle provider then that mac algorithm will be available, e.g.

    Security.addProvider(new BouncyCastleProvider()); 
    Mac mac = Mac.getInstance("ISO9797ALG3MAC");
    

    Note: that Mac algorithm has been obsolete for decades.