private void calculateHMAC(byte[] key, byte[] message, int len, byte[] iKey, byte[] oKey, byte[] byteBuff, int[] intBuff) { Arrays.fill(iKey, 0, 64, (byte) 0x36); xor(iKey, key, 64); System.arraycopy(message, 0, iKey, 64, len); calculateHash(iKey, 64 + len, byteBuff, intBuff); Arrays.fill(oKey, 0, 64, (byte) 0x5c); xor(oKey, key, 64); System.arraycopy(result, 0, oKey, 64, 32); calculateHash(oKey, 64 + 32, byteBuff, intBuff); }
/** * Calculate the hash code for the given data. * * @param data the data to hash * @param nullData if the data should be filled with zeros after calculating * the hash code * @return the hash code */ public static byte[] getHash(byte[] data, boolean nullData) { int len = data.length; int intLen = getIntCount(len); byte[] byteBuff = new byte[intLen * 4]; int[] intBuff = new int[intLen]; SHA256 sha = new SHA256(); sha.calculateHash(data, len, byteBuff, intBuff); if (nullData) { sha.fillWithNull(); Arrays.fill(intBuff, 0); Arrays.fill(byteBuff, (byte) 0); Arrays.fill(data, (byte) 0); } return sha.result; }