- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 02-14-2019 09:33 AM
Knowledge on how encryption works is a prerequisite.
Its hard to find a JS library that runs perfectly with ServiceNow JavaSript Engine which supports ECMAScript5.
Libraries like CryptoJS by Google wouldn't work right away without modifications.
Yet lot of Encryption libraries are built on native functions like Uint8Array which are not supported by ES5.
SJCL is developer by Standford, works perfectly to perform AES 256-bit encryption.
By Default CBC mode is disabled from the original source hosted by Standford on Github.
Find the modified SJCL library with CBC mode enabled from my GitHub. Here is the link sjcl-CBC-enabled.
If you are using the modified SJCL from my Github, following are some of the easy steps to get it working.
- Download sjcl.zip, extract the file to any folder.
- created a Script Include in a scoped application and removed the auto generated script.
- Name the Script Include with any name, paste the contents from the extracted file to script field and save it.
- From server script access it with 'sjcl' available as global variable in server script.
- find out how to use it from the official documentation page
Below is a sample code to perform AES 256-bit encryption with IV in CBC mode
// tested in Jakarta, Kingston, London versions.
// you can choose any format like sjcl.codec.base32 or sjcl.codec.hex or sjcl.codec.bytes key = sjcl.codec.base64.toBits(" Your Secret Key in Base64 Format "); iv = sjcl.codec.base64.toBits(" Initialization Vector in Base64 Format "); message = sjcl.codec.utf8String.toBits("Message to be encrypted"); aes = new sjcl.cipher.aes(key);
// pass aes, message, iv as parameters. choose any mode, CBC is used in the below line of code var cipher = sjcl.mode["cbc"].encrypt(aes, message, iv);
// cipher contains encrypted information in bits. covert to any format with below code
var cipherHex = sjcl.codec.hex.fromBits(chipher) // returns encrypted information in hexadecimal string format.
var cipherBase64 = sjcl.codec.base64.fromBits(cipher) // returnsencrypted information in Base64 string format.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
HI,
I'm getting an error message
"sjcl" is not defined
Can you help?
Thanks,
Lior
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Lior, can you provide some more information on this error?
did you follow the steps to create and paste code in script include.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Got the same error - "sjcl" is not defined. I have followed the instructions (Create Script include - remove content and paste SJCL.js)
I have tried to create a new application and repeated the steps in there. Tried to call the "sjcl" and got "not defined". It was also not possible to call it with a syntax like new ScriptIncludeName(). sjcl .....
I think something essential is missing in the instructions. Can you help out ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hi, i am getting the same error. did you figure out a solution?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Name the script include as sjcl.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This was long time ago, let me check this again and get back in few days