utils/utils.js
function decryptAPIMResponse(body, private_key) {

  if (!body.key || !body.cipher) {
    throw new Error('bad handshake response from APIm');
  }

  var key = crypto.privateDecrypt(
    { key: private_key,
      padding: constants.RSA_PKCS1_PADDING },
    new Buffer(body.key, 'base64')
  );

  var iv = new Buffer(16);
  iv.fill(0);
  var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
  var plainText = decipher.update(body.cipher, 'base64', 'utf8');
  plainText += decipher.final('utf8');

  log.debug('handshake response payload:', plainText);
  return JSON.parse(plainText);
}
function decryptAPIMResponse(body, private_key) {

  if (!body.key || !body.cipher) {
    throw new Error('bad handshake response from APIm');
  }

  var key = crypto.privateDecrypt(
    { key: private_key,
      padding: constants.RSA_PKCS1_PADDING },
    new Buffer(body.key, 'base64')
  );

  var iv = new Buffer(16);
  iv.fill(0);
  var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
  var plainText = decipher.update(body.cipher, 'base64', 'utf8');
  plainText += decipher.final('utf8');

  log.debug('handshake response payload:', plainText);
  return JSON.parse(plainText);
}
This function decrypts and parses an encrypted response body sent by APIM
The body must be in the following format:

{
"key": "base64(encrypted_with_public_key(aes_256_symmetric_key))"
"cipher": "base64(encrypted_with_aes_256_key(json_payload_as_string))"
}
@param body
@param private_key