Skip to content

Instantly share code, notes, and snippets.

@jacqueskang
Last active June 24, 2020 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacqueskang/96c444ee01e6a4b37300aa49e8097513 to your computer and use it in GitHub Desktop.
Save jacqueskang/96c444ee01e6a4b37300aa49e8097513 to your computer and use it in GitHub Desktop.
Compute AWS SES SMTP password using powershell (could be integrated in CloudFormation template)
$key = "${SecretAccessKey}";
$region = "${AWS::Region}";
$date = "11111111";
$service = "ses";
$terminal = "aws4_request";
$message = "SendRawEmail";
$versionInBytes = 0x04;
function HmacSha256($text, $key2) {
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = $key2;
$hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($text));
}
$signature = [Text.Encoding]::UTF8.GetBytes("AWS4" + $key)
$signature = HmacSha256 "$date" $signature;
$signature = HmacSha256 "$region" $signature;
$signature = HmacSha256 "$service" $signature;
$signature = HmacSha256 "$terminal" $signature;
$signature = HmacSha256 "$message" $signature;
$signatureAndVersion = [System.Byte[]]::CreateInstance([System.Byte], $signature.Length + 1);
$signatureAndVersion[0] = $versionInBytes;
$signature.CopyTo($signatureAndVersion, 1);
$smtpPassword = [Convert]::ToBase64String($signatureAndVersion);
Write-Host $smtpPassword;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment