### Question:
Crypto { public static void hmacSha1Verify(byte[] key, byte[] in, byte[] expected) throws GeneralSecurityException { Mac hmac = Mac.getInstance(HMAC_TYPE); Key hmacKey = new SecretKeySpec(key, HMAC_TYPE); hmac.init(hmacKey); hmac.update(in); byte actual[] = hmac.doFinal(); if (actual.length != expected.length) { throw new GeneralSecurityException("HMAC verification failure"); } for (int i=0; i < actual.length; i++) { if (actual[i] != expected[i]) { throw new GeneralSecurityException("HMAC verification failure"); } } } private  Crypto(); static String getRandomString(int numBytes); static String getRandomDigits(int len); static byte[] getRandomBytes(int numBytes); static byte[] hmacSha1(byte[] key, byte[] in); static void hmacSha1Verify(byte[] key, byte[] in, byte[] expected); static byte[] aes128cbcEncrypt(byte[] key, byte[] plain); static byte[] aes128cbcEncryptWithIV(byte[] key, byte[] iv, byte[] plain); static byte[] aes128cbcDecrypt(byte[] key, byte[] cipherText); static byte[] aes128cbcDecryptWithIv(byte[] key, byte[] iv,
      byte[] cipherText, int offset); static byte[] concat(byte[] a, byte[] b); static final SecureRandom RAND; final static int CIPHER_KEY_LEN; final static int HMAC_SHA1_LEN; }### Answer:
@Test public void testHmacSha1Verify() throws Exception { String key = "abcd1234"; String val = "your mother is a hedgehog"; byte[] expected = { -21, 2, 47, -101, 9, -40, 18, 43, 76, 117, -51, 115, -122, -91, 39, 26, -18, 122, 30, 90, }; Crypto.hmacSha1Verify(key.getBytes(), val.getBytes(), expected); }
@Test(expected = GeneralSecurityException.class) public void testHmacSha1VerifyTampered() throws Exception { String key = "abcd1234"; String val = "your mother is a hedgehog"; byte[] expected = { -21, 2, 47, -101, 9, -40, 18, 43, 76, 117, -51, 115, -122, -91, 39, 0, -18, 122, 30, 90, }; Crypto.hmacSha1Verify(key.getBytes(), val.getBytes(), expected); }