RE: Using SuiteScript to encrypt a string as JWE

Hi everyone, I have a question regarding JWS and JWE using SuiteScript. Perhaps someone here can help me with their previous experience.

I’m currently working on a script to sign a payload using JWS. After signing, I need to encrypt it using JWE. I was able to accomplish the signing part by referring to an example I found on Stack Overflow, which I believe someone here may have answered.

However, I’m facing a challenge when it comes to using the built-in crypto module to encrypt the JWS payload in a JWE-compliant manner, using encryption algorithms like A256CBC-HS512 or RSA-OAEP-256. I haven’t been able to find a way or an example demonstrating this.

Does anyone here have experience with accomplishing this task? It goes without saying that I’m trying not to include any external library to achieve this.

borgesbruno Rookie Asked on June 15, 2023 in SuiteScript.
Add Comment
5 Answers

When I include the above code in a SuiteScript:

cryptojs.AES.encrypt("test value", "test key")

I’ve got the following error

crypto-js.js:79 Uncaught Error: Native crypto module could not be used to get secure random number.
at cryptoSecureRandomInt (/SuiteScripts/crypto-js/crypto-js.js:79:16)
at random (/SuiteScripts/crypto-js/crypto-js.js:371:29)
at execute (/SuiteScripts/crypto-js/crypto-js.js:4215:25)
at encrypt (/SuiteScripts/crypto-js/crypto-js.js:4266:34)
at encrypt (/SuiteScripts/crypto-js/crypto-js.js:3630:33)
at :program (eval in context:1:1)
at encryptAES256 (/SuiteScripts/multiplier_reverse_sync_scheduled_script.js:43:13)
at execute (/SuiteScripts/multiplier_reverse_sync_scheduled_script.js:114:22)
cryptoSecureRandomInt @ crypto-js.js:79
random @ crypto-js.js:371
execute @ crypto-js.js:4215
encrypt @ crypto-js.js:4266
encrypt @ crypto-js.js:3630
:program @ 28/eval in context:1
encryptAES256 @ scheduled_script.js:43
execute @ scheduled_script.js

Please help. Thanks in Advance!

Rookie Answered on June 16, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.