# Process Variable Encryption (scripting)

**URL:** <https://forum.camunda.io/t/process-variable-encryption-scripting/6705>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [March 26, 2018, 7:01pm UTC](https://forum.camunda.io/t/process-variable-encryption-scripting/6705 "2018-03-26T19:01:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![StephenOTT](https://forum.camunda.io/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@StephenOTT](https://forum.camunda.io/u/StephenOTT)\
**Post date:** [March 26, 2018, 7:01pm UTC](https://forum.camunda.io/t/process-variable-encryption-scripting/6705/1 "2018-03-26T19:01:00Z")

</div>

Has been talk for a while about encrypting process variables.

I had solved this a while back, but thought it was time to share some usage.

I pulled apart some older code, and simplified some of the functions for reuse.

> **[GitHub - StephenOTT/camunda-data-encryption-rsa: Camunda BPM Process Variable...](https://github.com/StephenOTT/camunda-data-encryption-rsa)**
>
> Camunda BPM Process Variable RSA encryption and Signed Object with SHA256 and RSA, using Nashorn Javascript - GitHub - StephenOTT/camunda-data-encryption-rsa: Camunda BPM Process Variable RSA encry...

In short you can do the following:

```javascript
load('classpath:rsaEncrypt.js')
var messageToSeal = 'This message is to be hidden'

var sealedObject = rsaSeal(messageToSeal, PUBLIC_KEY)
execution.setVariable('sealed_object', sealedObject)

```

Where the `PUBLIC_KEY` and `PRIVATE_KEY` is a variable loaded from the rsaEncrypt.js script

same for decrypt

```javascript
load('classpath:rsaEncrypt.js')
var sealedObject = execution.getVariable('sealed_object')
var unsealedObject = rsaUnseal(sealedObject, PRIVATE_KEY)
execution.setVariable('unsealed_object', unsealedObject)

```

 ![Cockpit](https://forum.camunda.io/uploads/default/original/2X/d/dc4cd8e2b486d1f965dee3141b4f4005ea177136.png)  
 ![rsa_raw_inspect](https://forum.camunda.io/uploads/default/original/2X/7/7d3e938b88121b228659133098221f2257aa48c4.png)  
 ![rsa_sealedobject_inspect_1_serial](https://forum.camunda.io/uploads/default/original/2X/0/0bd24dc61fc3dc8a4e8fcf9b84c6f5a9547798d6.png)  
 ![rsa_sealedobject_inspect_2_deserial](https://forum.camunda.io/uploads/default/original/2X/1/18421e486f1e70d87227eba59e473968a893f45e.png)

This uses the SealedObject class from Java to provide a object wrapper for RSA encryption.

Enjoy!

cross ref:  
[Encryption of variables in a cloud environment](https://forum.camunda.io/t/encryption-of-variables-in-a-cloud-environment/6692), [Data Encryption at Rest](https://forum.camunda.io/t/data-encryption-at-rest/575), [Data encryption in web application - padding method?](https://forum.camunda.io/t/data-encryption-in-web-application-padding-method/4605), [Encryption of DB password in the configuration file](https://forum.camunda.io/t/encryption-of-db-password-in-the-configuration-file/2726), [Encrypted/hidden variables?](https://forum.camunda.io/t/encrypted-hidden-variables/3585), [Digitally signed or sealed process task data - #2 by Webcyberrob](https://forum.camunda.io/t/digitally-signed-or-sealed-process-task-data/6456/2)

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 11:09am UTC](https://forum.camunda.io/t/process-variable-encryption-scripting/6705/2 "2024-01-30T11:09:58Z")

</div>

Closed on January 30, 2024, 11:09am UTC


