Created
May 6, 2019 17:30
-
-
Save SamStenton/e672b7dca1cb3ad84bd4612b43cb5c0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const fs = require('fs'); | |
const pem = fs.readFileSync('./pem.pem', 'utf8') | |
const sha = crypto.createHash('sha512'); | |
sha.update(JSON.stringify({"item": "test"})); | |
const digest = sha.digest('base64'); | |
const url = 'put /api/v1'; | |
const date = new Date(); // this is the wrong format | |
const headers = `(request-target): ${url} Date: ${date} Digest: ${digest || 'X'}` | |
const sign = crypto.createSign('rsa-sha256'); | |
sign.update(headers); | |
sign.end(); | |
const signature = sign.sign(pem, 'base64'); | |
const UUID = 1234; | |
const Authorization = `Bearer ""; Signature keyid="${UUID}",algorithm="rsa-sha256",headers="${headers}",signature="${signature}"`; | |
console.log(Authorization); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment