cryptojs class to script include

ShAn21
Tera Guru

Hi Team,

How can we copy the full contents of cryptoJS from CDN to script include and start using it server side?

https://cdnjs.com/libraries/crypto-js

 

Is there any other source we can copy as well I am ok with it. Please let me know if you have any feedback

 

Thanks

1 ACCEPTED SOLUTION

Hi @jMarshal 

The below code works as is in script include. The only catch is it works only in custom scope.

https://gist.github.com/vetsin/117cfe99ab0f87c1ac2d5c6387d1f7b4

 

Thanks

View solution in original post

5 REPLIES 5

jMarshal
Mega Sage
Mega Sage

I think ServiceNow will need to bring this library in, to make it available natively in the platform -- not something you can "import" or "link-to". You can petition them to make it available natively through the ideation method in Now Support.

The easiest and "recommended" method is to simply create your own script include with the content from CDN - though that will come with some required upkeep (when new versions of the library are published, you'll need to update your script include.

 

There may be a way to write a script (depending on what hooks or APIs are available from the source), which would integrate the library by way of constant replication --> IE. set up a daily rebuild of a user-defined script include, based on the published library from CDN...

Hi Marshal,

I found an article below where they have given a sample but somehow does not seem to work as expected.

https://gist.github.com/igable/4bdcd90f78a8b2b07581

 

I am unable to call this script include. It says 'undefined is not a function'.

function getVal(val) {
// gs.log("veracode newkNonce: " + new global.Crypto.lib.WordArray.random(nonceSize).toString().toUpperCase());
return new CryptoJS.lib.WordArray.random(val).toString().toUpperCase();

}

 

Thanks

Maybe try separating the return value's functions into a few lines...I'm not sure about calling custom script includes with methods added from other libraries.

var test = data.functionNameFromCustomScriptInclude();

test = test.functionFromOtherLibrary();

test = test.toString();

 

...etc...

 

...also, I assume you used "# include" for your custom script include at the top of your script already?

Hi @jMarshal 

The below code works as is in script include. The only catch is it works only in custom scope.

https://gist.github.com/vetsin/117cfe99ab0f87c1ac2d5c6387d1f7b4

 

Thanks