Example inputs: | Variable | Value | | --- | --- | | key | `the shared secret key here` | | message | `the message to hash here` | Reference outputs for example inputs above: | Type | Hash | | --- | --- | | as hexit | `4643978965ffcec6e6d73b36a39ae43ceb15f7ef8131b8307862ebc560e7f988` | | as base64 | `RkOXiWX/zsbm1zs2o5rkPOsV9++BMbgweGLrxWDn+Yg=` | --- ## PHP ```php x.ToString("x2"))); // to base64 Convert.ToBase64String(hashmessage); } } ``` ## Java ```java import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.security.NoSuchAlgorithmException; import java.security.InvalidKeyException; import javax.xml.bind.DatatypeConverter; class Main { public static void main(String[] args) { try { String key = "the shared secret key here"; String message = "the message to hash here"; Mac hasher = Mac.getInstance("HmacSHA256"); hasher.init(new SecretKeySpec(key.getBytes(), "HmacSHA256")); byte[] hash = hasher.doFinal(message.getBytes()); // to lowercase hexits DatatypeConverter.printHexBinary(hash); // to base64 DatatypeConverter.printBase64Binary(hash); } catch (NoSuchAlgorithmException e) {} catch (InvalidKeyException e) {} } } ```