@Test public void encryptHmacSha256() throws Exception { String origin = "a12345678"; String key = "testKey"; String result = Coder.encryptHmacSha256(origin, key); logger.info("encryptHmacSha256, origin: [{}], key: [{}], result: [{}]", origin, key, result); }
public static String encryptHmacSha256(String data, String key) throws Exception { Mac sha256Hmac = Mac.getInstance(KEY_HmacSHA256); SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), KEY_HmacSHA256); sha256Hmac.init(secretKey); byte[] byteArray = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte item : byteArray) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } return sb.toString().toUpperCase(); }
Coder { public static String encryptHmacSha256(String data, String key) throws Exception { Mac sha256Hmac = Mac.getInstance(KEY_HmacSHA256); SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), KEY_HmacSHA256); sha256Hmac.init(secretKey); byte[] byteArray = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte item : byteArray) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } return sb.toString().toUpperCase(); } }
Coder { public static String encryptHmacSha256(String data, String key) throws Exception { Mac sha256Hmac = Mac.getInstance(KEY_HmacSHA256); SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), KEY_HmacSHA256); sha256Hmac.init(secretKey); byte[] byteArray = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte item : byteArray) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } return sb.toString().toUpperCase(); } private  Coder(); }
Coder { public static String encryptHmacSha256(String data, String key) throws Exception { Mac sha256Hmac = Mac.getInstance(KEY_HmacSHA256); SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), KEY_HmacSHA256); sha256Hmac.init(secretKey); byte[] byteArray = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte item : byteArray) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } return sb.toString().toUpperCase(); } private  Coder(); static String checkMd5(String originStr); static String checkMd5(byte[] msg); static String encryptPassWithSlat(String passwordMd5, String key); static String decryptPsWithSlat(String desPassword, String key); static boolean manyMd5PasswordCompare(String originPassword, String predictPassword, int loop); static String encryptHex(byte[] b); static byte[] decryptHex(String s); static String encodeBASE64(byte[] key); static byte[] decodeBASE64(String key); static String encodeMd5StrAndBase64(String origin); static String encodeMd5ByteAndBase64(String origin); static String encodeSHA1(String data); static String encodeSHA1ByDigestUtils(String data); static String encodeSHA256(String data); static String encodeSHA256ByDigestUtils(String data); static String initMacKey(); static byte[] encryptHMAC(byte[] data, String key); static String encryptHmacSha256(String data, String key); static String unicodeToCn(String unicode); static String cnToUnicode(String cn); }
Coder { public static String encryptHmacSha256(String data, String key) throws Exception { Mac sha256Hmac = Mac.getInstance(KEY_HmacSHA256); SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), KEY_HmacSHA256); sha256Hmac.init(secretKey); byte[] byteArray = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte item : byteArray) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } return sb.toString().toUpperCase(); } private  Coder(); static String checkMd5(String originStr); static String checkMd5(byte[] msg); static String encryptPassWithSlat(String passwordMd5, String key); static String decryptPsWithSlat(String desPassword, String key); static boolean manyMd5PasswordCompare(String originPassword, String predictPassword, int loop); static String encryptHex(byte[] b); static byte[] decryptHex(String s); static String encodeBASE64(byte[] key); static byte[] decodeBASE64(String key); static String encodeMd5StrAndBase64(String origin); static String encodeMd5ByteAndBase64(String origin); static String encodeSHA1(String data); static String encodeSHA1ByDigestUtils(String data); static String encodeSHA256(String data); static String encodeSHA256ByDigestUtils(String data); static String initMacKey(); static byte[] encryptHMAC(byte[] data, String key); static String encryptHmacSha256(String data, String key); static String unicodeToCn(String unicode); static String cnToUnicode(String cn);  }