- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 07:01 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 07:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 12:58 AM
Figured it out and it works
- Download latest CryptoJS package http://code.google.com/p/crypto-js/downloads/list
- From the zipped 'components' folder, extract core.js file and .js files for desired algorithm. example sha256.js
- In ServiceNow instance create a new scoped application
- Within that scope application, create a new Script Include
- In the Script Include script, add code below and ENSURE to copy and paste contents from the extracted .js files (can use Notepad to open them)
/** copy and paste contents of core.js
* should start with 'var CryptoJS = CryptoJS ||' etc.
* /
/** copy and paste contents of the chosen algorith js file
* example of sha256.js
* should start with '(function (Math) {' etc.
* /
//Script include definition here with SHA256 example
var MyCryptoScript = Class.create();
MyCryptoScript.prototype = {
initialize: function() {
},
hashSHA256: function(input) {
return CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
},
type: 'MyCryptoScript'
};
- Test calling the Script Include
var crypto = new MyCryptoScript();
var hash = crypto.hashSHA256('your input string');
gs.info('SHA-256 Hash: ' + hash);