server/boot/load-model.js
function addSignatureHeaders(body, headers, keyId, private_key) {
  var sign = function(str, private_key) {
    var sign = Crypto.createSign('RSA-SHA256');
    sign.update(str);
    return sign.sign(private_key, 'base64');
  };

  var sha256 = function(str, encoding) {
    var bodyStr = JSON.stringify(str);
    var hash = Crypto.createHash('sha256');
    hash.update(bodyStr);
    return hash.digest(encoding);
  };

  if (!headers) {
    headers = {};
  }

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

  if (!headers.digest) {
    headers.digest = 'SHA256=' + sha256(body, '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="' + sign(combine([ 'date', 'digest' ], headers), private_key) + '"';

  return headers;
}
function addSignatureHeaders(body, headers, keyId, private_key) {
  var sign = function(str, private_key) {
    var sign = Crypto.createSign('RSA-SHA256');
    sign.update(str);
    return sign.sign(private_key, 'base64');
  };

  var sha256 = function(str, encoding) {
    var bodyStr = JSON.stringify(str);
    var hash = Crypto.createHash('sha256');
    hash.update(bodyStr);
    return hash.digest(encoding);
  };

  if (!headers) {
    headers = {};
  }

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

  if (!headers.digest) {
    headers.digest = 'SHA256=' + sha256(body, '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="' + sign(combine([ 'date', 'digest' ], headers), private_key) + '"';

  return headers;
}
function addSignatureHeaders ( body , headers , keyId , private_key ) { var sign = function ( str , private_key ) { var sign = Crypto . createSign ( 'RSA-SHA256' ) ; sign . update ( str ) ; return sign . sign ( private_key , 'base64' ) ; } ; var sha256 = function ( str , encoding ) { var bodyStr = JSON . stringify ( str ) ; var hash = Crypto . createHash ( 'sha256' ) ; hash . update ( bodyStr ) ; return hash . digest ( encoding ) ; } ; if ( ! headers ) { headers = { } ; } if ( ! headers . date ) { headers . date = ( new Date ( ) ) . toUTCString ( ) ; } if ( ! headers . digest ) { headers . digest = 'SHA256=' + sha256 ( body , '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="' + sign ( combine ( [ 'date' , 'digest' ] , headers ) , private_key ) + '"' ; 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 private_key (String): RSA Private key to be used for the signature
@returns {*}
Compute the signature headers date digest and authorization headers according to IETF I - D draft - cavage - http - signatures - 05 using rsa - sha256 algorithm