StaticTicketCrypto { public static boolean verifyHMAC(MacAlgorithm macalgo, byte[] mac, byte[] plaintext, byte[] key) throws CryptoException { byte[] newmac = generateHMAC(macalgo, plaintext, key); boolean result = Arrays.equals(mac, newmac); return result; } private  StaticTicketCrypto(); static byte[] encrypt(CipherAlgorithm cipherAlgorithm, byte[] plaintextUnpadded, byte[] key, byte[] iv); static byte[] decrypt(CipherAlgorithm cipherAlgorithm, byte[] ciphertext, byte[] key, byte[] iv); static byte[] generateHMAC(MacAlgorithm macAlgorithm, byte[] plaintext, byte[] key); static boolean verifyHMAC(MacAlgorithm macalgo, byte[] mac, byte[] plaintext, byte[] key);  }
@Test public void testVerifyHMAC_SHA256() throws CryptoException { LOGGER.info("Verify HMAC SHA256"); byte[] mac = ArrayConverter .hexStringToByteArray("b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"); byte[] plaintext = ArrayConverter.hexStringToByteArray("4869205468657265"); byte[] key = ArrayConverter.hexStringToByteArray("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"); boolean expResult = true; boolean result = StaticTicketCrypto.verifyHMAC(MacAlgorithm.HMAC_SHA256, mac, plaintext, key); assertEquals(expResult, result); }