Some sun.misc internal APIs are deprectaed in JDK 9 and will be encapsulated or removed in a future release.
public static String getHmac(String entity, String salt) throws Exception{ Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(salt.getBytes(), "HmacSHA1")); byte[] bs = mac.doFinal(entity.getBytes()); return new HexDumpEncoder().encode(bs); // use your favorite hex converter }
private static void printHex(HexDumpEncoder dump, byte[] bytes) { if (bytes == null) { System.out.println("(key bytes not available)"); } else { try { dump.encodeBuffer(bytes, System.out); } catch (IOException e) { // just for debugging, ignore this } } }
new sun.misc.HexDumpEncoder().encode(result).substring(6);
private static void printHex(HexDumpEncoder dump, byte[] bytes) { if (bytes == null) { System.out.println("(key bytes not available)"); } else { try { dump.encodeBuffer(bytes, System.out); } catch (IOException e) { // just for debugging, ignore this } } }
HexDumpEncoder dump = new HexDumpEncoder();
HexDumpEncoder dump = new HexDumpEncoder();
HexDumpEncoder dump = new HexDumpEncoder();
HexDumpEncoder dump = new HexDumpEncoder();