utils/utils.js
function addSignatureHeaders(body, headers, keyId, key) {
  if (!headers) {
    headers = {};
  }

  if (!headers.date) {
    headers.date = (new Date()).toUTCString();
  }

  if (!headers.digest) {
    headers.digest = 'SHA256=' + hashMsg(JSON.stringify(body), 'sha256')
        .toString('base64');
  }


  var combine = function(names, headers) {
    var parts = [];
    names.forEach(function(e) {
      parts.push(e + ': ' + headers[e]);
    });
    return parts.join('\n');
  };

  headers.authorization = 'Signature ' +
    'keyId="' + keyId + '", ' +
    'headers="date digest", ' +
    'algorithm="rsa-sha256", ' +
    'signature="' +
    signMsg(combine([ 'date', 'digest' ], headers), key, 'RSA-SHA256')
      .toString('base64') + '"';

  return headers;
}
function addSignatureHeaders(body, headers, keyId, key) {
  if (!headers) {
    headers = {};
  }

  if (!headers.date) {
    headers.date = (new Date()).toUTCString();
  }

  if (!headers.digest) {
    headers.digest = 'SHA256=' + hashMsg(JSON.stringify(body), 'sha256')
        .toString('base64');
  }


  var combine = function(names, headers) {
    var parts = [];
    names.forEach(function(e) {
      parts.push(e + ': ' + headers[e]);
    });
    return parts.join('\n');
  };

  headers.authorization = 'Signature ' +
    'keyId="' + keyId + '", ' +
    'headers="date digest", ' +
    'algorithm="rsa-sha256", ' +
    'signature="' +
    signMsg(combine([ 'date', 'digest' ], headers), key, 'RSA-SHA256')
      .toString('base64') + '"';

  return headers;
}
Compute the signature headers "date", "digest", and "authorization" headers
according to IETF I-D draft-cavage-http-signatures-05 using rsa-sha256 algorithm

If the `date` header already exists in the input, it's used as-is
If the `digest` header already exists in the input, it's used as-is (which means that body is ignored)


@param body (String): Message body (ignored if there is already a digest header)
@param headers (Object): Contains the existing list of headers
@param keyId (String): Identifier for the private key, ends up in the "keyId" param of the authorization header
@param key (String): RSA Private key to be used for the signature
@returns {*}