@Test public void testHMAC() { HMAC h1 = new HMAC(); assertNotNull(h1); try { Provider sp = new com.sun.crypto.provider.SunJCE(); Security.addProvider(sp); } catch (Exception e) { fail("Problem loading crypto provider" + e); } byte[] hmac = h1.computeMac(); assertNull("Currently HMAC is broken since you can't actually " + "set the keyData or data elements. This test will break once someone fixes that", hmac); }
public byte[] computeMac() { Mac hm = null; byte[] result = null; if (log.isDebugEnabled()) { log.debug("Key data: {}", byteArrayToHex(keyBytes)); log.debug("Hash data: {}", byteArrayToHex(dataBytes)); log.debug("Algorithm: {}", ALGORITHM_ID); } try { hm = Mac.getInstance(ALGORITHM_ID); Key k1 = new SecretKeySpec(keyBytes, 0, keyBytes.length, ALGORITHM_ID); hm.init(k1); result = hm.doFinal(dataBytes); } catch (Exception e) { log.warn("Bad algorithm or crypto library problem", e); } return result; }
HMAC { public byte[] computeMac() { Mac hm = null; byte[] result = null; if (log.isDebugEnabled()) { log.debug("Key data: {}", byteArrayToHex(keyBytes)); log.debug("Hash data: {}", byteArrayToHex(dataBytes)); log.debug("Algorithm: {}", ALGORITHM_ID); } try { hm = Mac.getInstance(ALGORITHM_ID); Key k1 = new SecretKeySpec(keyBytes, 0, keyBytes.length, ALGORITHM_ID); hm.init(k1); result = hm.doFinal(dataBytes); } catch (Exception e) { log.warn("Bad algorithm or crypto library problem", e); } return result; } }
HMAC { public byte[] computeMac() { Mac hm = null; byte[] result = null; if (log.isDebugEnabled()) { log.debug("Key data: {}", byteArrayToHex(keyBytes)); log.debug("Hash data: {}", byteArrayToHex(dataBytes)); log.debug("Algorithm: {}", ALGORITHM_ID); } try { hm = Mac.getInstance(ALGORITHM_ID); Key k1 = new SecretKeySpec(keyBytes, 0, keyBytes.length, ALGORITHM_ID); hm.init(k1); result = hm.doFinal(dataBytes); } catch (Exception e) { log.warn("Bad algorithm or crypto library problem", e); } return result; }  }
HMAC { public byte[] computeMac() { Mac hm = null; byte[] result = null; if (log.isDebugEnabled()) { log.debug("Key data: {}", byteArrayToHex(keyBytes)); log.debug("Hash data: {}", byteArrayToHex(dataBytes)); log.debug("Algorithm: {}", ALGORITHM_ID); } try { hm = Mac.getInstance(ALGORITHM_ID); Key k1 = new SecretKeySpec(keyBytes, 0, keyBytes.length, ALGORITHM_ID); hm.init(k1); result = hm.doFinal(dataBytes); } catch (Exception e) { log.warn("Bad algorithm or crypto library problem", e); } return result; }  static final boolean isHexStringChar(char c); static final boolean isHex(String sampleData); static final boolean isHex(byte[] sampleData, int len); static final byte[] hexToByteArray(String str, boolean rev); static final String byteArrayToHex(byte[] a); byte[] readDataFile(File f, int minValidLength); byte[] readDataStream(InputStream is, int minValidLength); byte[] computeMac(); }
HMAC { public byte[] computeMac() { Mac hm = null; byte[] result = null; if (log.isDebugEnabled()) { log.debug("Key data: {}", byteArrayToHex(keyBytes)); log.debug("Hash data: {}", byteArrayToHex(dataBytes)); log.debug("Algorithm: {}", ALGORITHM_ID); } try { hm = Mac.getInstance(ALGORITHM_ID); Key k1 = new SecretKeySpec(keyBytes, 0, keyBytes.length, ALGORITHM_ID); hm.init(k1); result = hm.doFinal(dataBytes); } catch (Exception e) { log.warn("Bad algorithm or crypto library problem", e); } return result; }  static final boolean isHexStringChar(char c); static final boolean isHex(String sampleData); static final boolean isHex(byte[] sampleData, int len); static final byte[] hexToByteArray(String str, boolean rev); static final String byteArrayToHex(byte[] a); byte[] readDataFile(File f, int minValidLength); byte[] readDataStream(InputStream is, int minValidLength); byte[] computeMac(); static final String ALGORITHM_ID; static final int MIN_LENGTH; static final int BUF_LENGTH; }