Skip to content

Instantly share code, notes, and snippets.

@grosscorporation
Last active August 4, 2018 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosscorporation/424236be927aaa7554b3e2eac06da746 to your computer and use it in GitHub Desktop.
Save grosscorporation/424236be927aaa7554b3e2eac06da746 to your computer and use it in GitHub Desktop.
HMAC-SHA256 signature crypto
let now = new Date ();
let ISODate = new Date ( now.toISOString () );
let TimeStamp = ISODate.getTime ();
let api_access_key = "key1";
let api_secret_key = "key2";
let url = "https://test-emoney-services.w-ha.com/api/";
let body = {
"subscriber" : {
"lastname" : "Martin",
"firstname" : "Philippe",
"birthdate" : "1986-03-01",
"nationality" : "FRA"
},
"address" : {
"label1" : "12 rue de Stalingrad",
"zip_code" : "92800",
"city" : "Puteaux",
"country" : "FRA"
},
"email" : "m.philippe@wha.fr",
"tag" : "account_type1"
};
let hmac = crypto.createHmac ( 'sha256', api_secret_key );
hmac.update ( api_access_key + ':' + TimeStamp + ':1:' + JSON.stringify ( body ) );
let signature = hmac.digest ( 'hex' );
let options = {
method : 'post',
url : url + 'accounts/standard',
json : true,
headers : {
'Authorization' : 'AUTH ' + api_access_key + ':' + TimeStamp + ':1:' + signature,
'Content-Type' : 'application/json'
},
body : body
};
request ( options, function callback ( error, response, body ) {
if ( error ) {
res.send ( error )
} else {
res.send ( body );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment