-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (19 loc) · 740 Bytes
/
index.js
File metadata and controls
24 lines (19 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const crypto = require('crypto');
// The values of the following variables should always stay the same.
const date = "11111111";
const service = "ses";
const terminal = "aws4_request";
const message = "SendRawEmail";
const versionInBytes = Buffer.from([0x04]);
function sign(msg, key) {
return crypto.createHmac('sha256', key).update(msg).digest();
}
module.exports.calculateKey = function (key, region) {
let signature = sign(date, "AWS4" + key);
signature = sign(region, signature);
signature = sign(service, signature);
signature = sign(terminal, signature);
signature = sign(message, signature);
let signatureAndVersion = Buffer.concat([versionInBytes, signature]);
return signatureAndVersion.toString('base64');
}