/** * 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; }
/** * Calculate the hash-based message authentication code. * * @param key the key * @param message the message * @return the hash */ public static byte[] getHMAC(byte[] key, byte[] message) { key = normalizeKeyForHMAC(key); int len = message.length; int byteLen = 64 + Math.max(32, len); int intLen = getIntCount(byteLen); byte[] byteBuff = new byte[intLen * 4]; int[] intBuff = new int[intLen]; SHA256 sha = new SHA256(); byte[] iKey = new byte[64 + len]; byte[] oKey = new byte[64 + 32]; sha.calculateHMAC(key, message, len, iKey, oKey, byteBuff, intBuff); return sha.result; }
int len = 64 + Math.max(32, salt.length + 4); byte[] message = new byte[len]; int intLen = getIntCount(len); byte[] byteBuff = new byte[intLen * 4]; int[] intBuff = new int[intLen];
int[] hh = this.hh; byte[] result = this.result; int intLen = getIntCount(len); System.arraycopy(data, 0, byteBuff, 0, len); byteBuff[len] = (byte) 0x80;