Java method which can provide the same output as Python method for HMAC-SHA256 in Hex
I am now trying to encode the string using HMAC-SHA256 using Java. The encoded string required to match another set of encoded string generated by Python using hmac.new(mySecret, myPolicy, hashlib.sha256).hexdigest() . I have tried Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), "HmacSHA256"); sha256_HMAC.init(secretKey); byte[] hash = sha256_HMAC.doFinal(policy.getBytes()); byte[] hexB = new Hex().encode(hash); String check = Hex.encodeHexString(hash); String sha256 = DigestUtils.sha256Hex(secret.getBytes()); after I print them