@Test public void createHmac() { final byte[] headerData = "The quick".getBytes(); Header header = mock(Header.class); doReturn(headerData.length).when(header).size(); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { byte[] input = (byte[])invocation.getArguments()[0]; System.arraycopy(headerData, 0, input, 0, headerData.length); return null; } }).when(header).store(any(byte[].class), anyInt(), anyByte()); Key key = new SecretKeySpec("key".getBytes(), "AES"); HmacCreator creator = new HmacCreator(header, key) {}; byte[] hmac = creator.createHmac(" brown fox jumps over the lazy dog".getBytes()); byte[] hmacExpected = CryptoUnitUtils.hexToBytes("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"); assertArrayEquals(hmacExpected, hmac); }
byte[] createHmac(byte[] input) { byte[] rawHeader = new byte[header.size()]; header.store(rawHeader, 0, header.getFlags()); mac.update(rawHeader); return mac.doFinal(input); }
HmacCreator { byte[] createHmac(byte[] input) { byte[] rawHeader = new byte[header.size()]; header.store(rawHeader, 0, header.getFlags()); mac.update(rawHeader); return mac.doFinal(input); } }
HmacCreator { byte[] createHmac(byte[] input) { byte[] rawHeader = new byte[header.size()]; header.store(rawHeader, 0, header.getFlags()); mac.update(rawHeader); return mac.doFinal(input); } HmacCreator(Header header, Key key); }
HmacCreator { byte[] createHmac(byte[] input) { byte[] rawHeader = new byte[header.size()]; header.store(rawHeader, 0, header.getFlags()); mac.update(rawHeader); return mac.doFinal(input); } HmacCreator(Header header, Key key);  }
HmacCreator { byte[] createHmac(byte[] input) { byte[] rawHeader = new byte[header.size()]; header.store(rawHeader, 0, header.getFlags()); mac.update(rawHeader); return mac.doFinal(input); } HmacCreator(Header header, Key key);  static final String DEFAULT_HMAC_ALGORITHM; }