KeyGenerator keyGen = KeyGenerator.getInstance('DES') The KeyGenerator class provides getInstance() method which accepts a String variable representing the required key-generating algorithm and returns a KeyGenerator object that generates secret keys.Ĭreate KeyGenerator object using the getInstance() method as shown below. Follow the steps given below to create message authentication code using this class. In Java the Mac class of the javax.crypto package provides the functionality of message authentication code. The process of using MAC for authentication is depicted in the following illustration − For establishing MAC process, the sender and receiver share a symmetric key K.Įssentially, a MAC is an encrypted checksum generated on the underlying message that is sent along with a message to ensure message authentication. MAC ( Message Authentication Code) algorithm is a symmetric key cryptographic technique to provide message authentication.