@Test public void testGenerateMac() { String[][] example = new String[][]{ new String[]{ "5334a31e27d5a4ea3dd815ffc8a0483b1a370ef32baf4f26349985027ab01d6e1fa23e6e0aea328814d3e2aefaf2c1f47b96c86ec24dc5cd66d7050fb249ec03d985b4793a9703f7ac189ecef67fb5a29797e2952a3efd12fe5565465b1fadeaaced304d142b2d2d46f3e8986ac3e2", "592bbbd0596b97439ee041e7c0679aba846031e66730c5f20e3626d59bfd22bd", "9600a5081753d9bc0f0855d55a592925ea5784a6c45c7a5c161ffa82e140e4eb" }, new String[]{ "ebef0d152fe4c889d2a903ec5c3adfdd7c8c8e207679c86475f3cf9d48f4455766953d3a4305fd37b35ae2e87082daa649bb51e55940c566ec21772a11a6606ccde7b26b88ac5e5f6e9569787041324ab978e695656776cd961139713ebe3fdd23027a205683f108579e162a839e69", "539d8bea635f1b8cba4ab4802e7c557dad1e097df6c4b75a6aab0385fd4e2cb9", "8dabc02eb079e935ce7dc4ec6639aaad8dc2de1275479465e86b6a475f7ebe24" }, new String[]{ "30c50f3c3bba03c6186ca65675b1b447b9dd803cbd86d12708ea9581a6ad5e930c0064c2c549cb354cace5e2a860abfb11f66589858c11751eceeaa11b61c8eee3d60646a26b39d9d8744b8dadc2cb7568e63e55f04428fea52c073b94ee570fe7f13266b338094d5ee85970129c12", "2cb813ecf4a1cc47fd80817f63f88bb17b35dcb34f08facf186dbba67c640c08", "973d56c4662e64db58d097c156290f2b7efecfbc357cfa8b7e71b032dacedeec" } }; for (String[] testData : example) { byte[] cipherText = NumericUtil.hexToBytes(testData[0]); byte[] derivedKey = NumericUtil.hexToBytes(testData[1]); String expected = testData[2]; assertEquals(expected, NumericUtil.bytesToHex(Hash.generateMac(derivedKey, cipherText))); } }
public static byte[] generateMac(byte[] derivedKey, byte[] cipherText) { byte[] result = new byte[16 + cipherText.length]; System.arraycopy(derivedKey, 16, result, 0, 16); System.arraycopy(cipherText, 0, result, 16, cipherText.length); return Hash.keccak256(result); }
Hash { public static byte[] generateMac(byte[] derivedKey, byte[] cipherText) { byte[] result = new byte[16 + cipherText.length]; System.arraycopy(derivedKey, 16, result, 0, 16); System.arraycopy(cipherText, 0, result, 16, cipherText.length); return Hash.keccak256(result); } }
Hash { public static byte[] generateMac(byte[] derivedKey, byte[] cipherText) { byte[] result = new byte[16 + cipherText.length]; System.arraycopy(derivedKey, 16, result, 0, 16); System.arraycopy(cipherText, 0, result, 16, cipherText.length); return Hash.keccak256(result); }  }
Hash { public static byte[] generateMac(byte[] derivedKey, byte[] cipherText) { byte[] result = new byte[16 + cipherText.length]; System.arraycopy(derivedKey, 16, result, 0, 16); System.arraycopy(cipherText, 0, result, 16, cipherText.length); return Hash.keccak256(result); }  static String keccak256(String hex); static byte[] keccak256(byte[] input); static byte[] generateMac(byte[] derivedKey, byte[] cipherText); static String sha256(String hexInput); static byte[] sha256(byte[] input); static byte[] hmacSHA256(byte[] key, byte[] data); static byte[] merkleHash(byte[] oriData); }
Hash { public static byte[] generateMac(byte[] derivedKey, byte[] cipherText) { byte[] result = new byte[16 + cipherText.length]; System.arraycopy(derivedKey, 16, result, 0, 16); System.arraycopy(cipherText, 0, result, 16, cipherText.length); return Hash.keccak256(result); }  static String keccak256(String hex); static byte[] keccak256(byte[] input); static byte[] generateMac(byte[] derivedKey, byte[] cipherText); static String sha256(String hexInput); static byte[] sha256(byte[] input); static byte[] hmacSHA256(byte[] key, byte[] data); static byte[] merkleHash(byte[] oriData);  }