Last active
September 25, 2024 06:01
-
-
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)
This file contains hidden or 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
$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