D:\IBM>java MessageAuthenticationCodeExample "This is a test!"
Start generating key
Finish generating key
SunJCE Provider (implements DES, Triple DES, Blowfish, PBE, Diffie-Hellman,
HMAC-MD5, HMAC-SHA1)
MAC:
Dkdj47x4#.@kd#n8a-x>
Note that the key generation takes a long time because the code is generating excellent quality pseudo-random numbers using the timing of thread behavior. Once the first number is generated, the others take much less time.
Also, notice that unlike the message digest, the message-authentication code uses a cryptographic provider. (For more on providers, see Security is enriched with third-party libraries.)