HMAC { public static byte[] generateKey(Hash hash) { try { KeyGenerator generator = KeyGenerator.getInstance(hash.algorithm); generator.init(128); return generator.generateKey().getEncoded(); } catch (NoSuchAlgorithmException e) { throw new Error(e); } } HMAC(byte[] key, Hash hash); static byte[] generateKey(Hash hash); byte[] digest(byte[] message);  }
@Test void generateKey() { byte[] key = HMAC.generateKey(HMAC.Hash.SHA512); HMAC hmac = new HMAC(key, HMAC.Hash.SHA512); byte[] bytes = hmac.digest(Strings.bytes("hello")); assertNotNull(bytes); }