- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2022 07:20 AM
Hello,
I've tried to implement some variant of CryptoJS for making an authentication token. The problem is when i run the code snippet below I encounter this error:
Evaluator.evaluateString() problem: java.lang.SecurityException: Encountered scriptable of unknown type Object
var key = "sample_key";
var secret = CryptoJS.enc.Base64.parse(key);
var str = CryptoJS.HmacSHA512("sample_data", secret);
str = CryptoJS.enc.Base64.stringify(str);
I think the error is occuring when trying to create the HmacSHA512 encoding. The code works fine running in a node.js environment.
I have created a Script Include called CryptoJS with the code attached in the file.
Anyone have some experience working with HmacSHA512, any help is appriciated.
Solved! Go to Solution.
- Labels:
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 01:11 AM
Not sure why that is. However I'll attach your file modified by me as described; I've tested it in both San Diego and Quebec. I assume if it works in those two, it should also work in Rome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 05:25 AM
Got it working, i could not be running the script from an scoped application. So i have to move the workflow to global to be able to run it. Thank you for the help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 06:34 AM
Your welcome! But not working from scope is strange. I did run all those examples in a scope. In fact I haven't tried running it in global :-). Perhaps you configured it to only be accessible from its own scope and tried to call it from a different scope?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2022 02:31 AM
I am encountering the same issue on line 68, I need to generate a signature using the following function:
Javascript compiler exception: Primitive type expected (had org.mozilla.javascript.Undefined instead) (sys_script_include.d955951db5b745102ed6e29bdb2d14e6.script; line 68) in: var CryptoJS = Class.create();
Any suggestions would be greatly appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 12:34 AM
Hello @-O- , It looks great to see this script is working as expected.
I do have a similar requirement and trying to generate the str by following the steps
1. Created script include with name CryptoJS by copying the text from your file into script part.
2. Executed the below script from Background scripts
var key = "sample_key";
var secret = CryptoJS.enc.Base64.parse(key);
var str = CryptoJS.HmacSHA512("sample_data", secret);
str = CryptoJS.enc.Base64.stringify(str);
gs.info("str::"+str);
Unfortunately, below is the error received at line 1927. It would be great help if you can guide us to have it implemeted. Thanks in advance!
Script execution error: Script Identifier: null.null.script, Error Description: Cannot read property "0" from undefined, Script ES Level: 0
Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "0" from undefined script : Line(1927) column(0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 07:23 PM
Have tried to "convert" the original library to a Script Include/ServiceNow "friendly" format.
Maybe it is useful.
It DOES NOT contain all the functionality in the original library; it only contains minimal SHA256 and SHA512 HMAC "support".
For something like:
(
function () {
var C = global.CryptoLib
var key = 'SecretKey01@';
var hasher = new C.algo.SHA512();
var hmac = new C.algo.HMAC(hasher, key);
var data = hmac.finalize('Lorem Ipsum...');
gs.debug(data.toString());
gs.debug(data.toString(C.enc.Base64));
}
)();