Digitally signed or sealed process task data

Here is some code we used previously when doing the RSA Encryption: Process Variable Encryption (scripting)

SignedObject Snippet:

function loadPrivateKey(fileNamePath, setGlobal){
  var keyBytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(fileNamePath))
  var spec = new java.security.spec.PKCS8EncodedKeySpec(keyBytes)
  var kf = java.security.KeyFactory.getInstance("RSA")
  var privateKey = kf.generatePrivate(spec)
  
  // Sets the global variable for Private Key usage
  if (setGlobal == true){
    PRIVATE_KEY = privateKey
  }
  return privateKey
}


function getEnvVar(variableName){
  return java.lang.System.getenv(variableName)
}


loadPrivateKey(getEnvVar('BPM_PRIVATE_KEY'), true)



var SignedObject = Java.type('java.security.SignedObject')
var Signature = Java.type('java.security.Signature')
var signingEngine = Signature.getInstance('SHA256withRSA');

function signObject(objectToSign, privateKey) {
  var signedObject = new SignedObject(objectToSign, privateKey, signingEngine)
  return signedObject
}

var myJsonJs = {
  "someKey1": "someValue1",
  "someKey2": [
    {
      "someInnerKey1": "someInnerValue1"
    },
    {
      "someInnerKey2": "someInnerValue2"
    }
  ]
}
var myJsonSpin = S(JSON.stringify(myJsonJs)) 
var mySignedObject = signObject(myJsonSpin.toString(), PRIVATE_KEY)
execution.setVariable('signedObject', mySignedObject)



1 Like