Skip to content

Instantly share code, notes, and snippets.

@simonr-cb
Created January 12, 2018 16:44
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 simonr-cb/c07f5eb252eebbb418408e033b44dcdd to your computer and use it in GitHub Desktop.
Save simonr-cb/c07f5eb252eebbb418408e033b44dcdd to your computer and use it in GitHub Desktop.
var secret = SHIPFAST_HMAC_SECRET
var hmac
...
...
var obfuscatedSecretData = Buffer.from(secret, 'base64')
var shipFastAPIKeyData = new Buffer("QXBwcm9vdidzIHRvdGFsbHkgYXdlc29tZSEh")
for (var i = 0; i < Math.min(obfuscatedSecretData.length, shipFastAPIKeyData.length); i++) {
obfuscatedSecretData[i] ^= shipFastAPIKeyData[i]
}
var obfuscatedSecret = new Buffer(obfuscatedSecretData).toString('base64')
hmac = crypto.createHmac('sha256', Buffer.from(obfuscatedSecret, 'base64'))
...
...
// Compute the request HMAC using the HMAC SHA-256 algorithm
...
...
// Check to see if our HMAC matches the one sent in the request header
// and send an error response if it doesn't
if (ourShipFastHMAC != requestShipFastHMAC) {
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment