Creating a JWT token in script using java cyrpto packages
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 12:12 AM
I have created a script include to generate JWT tokens for authorization purposes on a separately hosted web app.
The script include is in the global scope and accessible to all applications.
I am getting an "Illegal attempt to access class 'javax.crypto.Mac' via script" error when running the script include.
Code snippet:
signHMACSHA256: function(data, secret) { var mac = new Packages.javax.crypto.Mac.getInstance("HmacSHA256"); var secretKey = new Packages.javax.crypto.spec.SecretKeySpec(secret.getBytes(), "HmacSHA256"); mac.init(secretKey); var rawHmac = mac.doFinal(new java.lang.String(data).getBytes()); return GlideStringUtil.base64Encode(rawHmac).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); },
Any solutions to access this package? Or alternate solutions to generating JWT.
0 REPLIES 0