I am very new to Java and trying to use some Java code inside a custom sandbox environment that can support both java and javascript. It does not allow import or script statements though.
var sha256Hmac = javax.crypto.Mac.getInstance("HmacSHA256");
var secretKey = new javax.crypto.spec.SecretKeySpec(secret.getBytes(), "HmacSHA256");
sha256Hmac.init(secretKey);
When I print sha256Hmac, I get javax.crypto.Mac@7508cc45 and when I print secretKey, I get javax.crypto.spec.SecretKeySpec@fa75c355
I was able to use Hashmap and Base 64 like this and get the correct output
var hashMap = new java.util.HashMap();
hashMap.putAll(obj.getValues());
var payload = java.util.Base64.getUrlEncoder().encodeToString(hashMap.getBytes());