Skip to content

Instantly share code, notes, and snippets.

@MeLlamoPablo
Created February 13, 2018 08:39
Show Gist options
  • Save MeLlamoPablo/4da48793139741dbdf61cddcc785af4f to your computer and use it in GitHub Desktop.
Save MeLlamoPablo/4da48793139741dbdf61cddcc785af4f to your computer and use it in GitHub Desktop.
Node.js snippet that converts an AWS IAM secret access key to an AWS SES SMTP password
/*
* Implementation of the algorithm described here:
* https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
*/
const {createHmac} = require("crypto");
const key = process.env.KEY || (() => { throw new Error("Variable KEY not defined")} )();
const msg = "SendRawEmail";
const version = new Buffer(1);
version.writeUInt8(0x02, 0);
const signature = createHmac("sha256", key).update(msg).digest();
const signatureAndVer = Buffer.concat([version, signature]);
console.log(signatureAndVer.toString("base64"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment