HMAC { public byte[] digest(byte[] message) { if (key == null) throw new Error("key must not be null"); try { Mac mac = Mac.getInstance(hash.algorithm); SecretKey secretKey = new SecretKeySpec(key, hash.algorithm); mac.init(secretKey); return mac.doFinal(message); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new Error(e); } } HMAC(byte[] key, Hash hash); static byte[] generateKey(Hash hash); byte[] digest(byte[] message);  }
@Test void digestByMD5() { HMAC hmac = new HMAC(Strings.bytes("4VPDEtyUE"), HMAC.Hash.MD5); byte[] bytes = hmac.digest(Strings.bytes("hello")); assertNotNull(bytes); }
@Test void digestBySHA512() { HMAC hmac = new HMAC(Strings.bytes("4VPDEtyUE"), HMAC.Hash.SHA512); byte[] bytes = hmac.digest(Strings.bytes("hello")); assertNotNull(bytes); }