How to base64 encrypt rest message payload

Swapnil Shirsik
Giga Guru

Hi, i have created a rest post method and invoking it through business rule . I need to encrypt the payload.. how to do it? Is it done in rest message or in business rule or somewhere else?

Please help.

9 REPLIES 9

@Swapnil Shirsik  - please remove the quotes and try again

r.setRequestBody(encryptedPayload);

  

Thank you very much. I see the encrypted payload. My concern is the encrypted value is only 20 characters long alphanumeric value and it remains same even if i modify incident fields as request payload input. Is this expected? Or the encrypted payload should change each time and should increase if i include more fields in the request payload?

 

Do you know this?

@Swapnil Shirsik  - you can decrypt it and validate, for decrypting use this method:

var encryptedPayload = GlideStringUtil.base64Encode(json_payload);
var decryptedPayload = GlideStringUtil.base64Decode(encryptedPayload);
gs.log(decryptedPayload);

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

Yes, i tried it.. it is showing [Object Object]

 

I have defined the body as var body={....}

encrypted it

 

If i send encryptedpayload in r.setrequestBody it will give error 400 unacceptable data.

 

So I'm stringifying the encrypted payload as 

 

Var stri= JSON.stringify(encryptedPayload)

 

And now setting this in requestBody as

r.setrequestBody(stri)

 

So this time I'm getting 200 ok response but the decoded value is same in both cases as [object Object]

 

 

@Swapnil Shirsik  - please try this to log object

JSUtil.logObject(decryptedObject, "decryptedObj");