Skip to content

Instantly share code, notes, and snippets.

@tanelmae
Last active June 3, 2022 10:39
Show Gist options
  • Save tanelmae/2ba36e117558a46461bb89cd287487bd to your computer and use it in GitHub Desktop.
Save tanelmae/2ba36e117558a46461bb89cd287487bd to your computer and use it in GitHub Desktop.
Example how to generate AWS SES password from AWS secret key
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
// AWS documentation: https://docs.aws.amazon.com/ses/latest/dg/smtp-credentials.html#smtp-credentials-convert
var (
date = "11111111"
service = "ses"
message = "SendRawEmail"
terminal = "aws4_request"
version = 4
region = "us-east-1"
key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
)
func main() {
sig := sign([]byte("AWS4"+key), []byte(date))
sig = sign(sig, []byte(region))
sig = sign(sig, []byte(service))
sig = sign(sig, []byte(terminal))
sig = sign(sig, []byte(message))
sig = append([]byte{byte(version)}, sig...)
smtpPassword := base64.StdEncoding.EncodeToString(sig)
fmt.Println(smtpPassword)
}
func sign(key, msg []byte) []byte {
mac := hmac.New(sha256.New, key)
mac.Write(msg)
return mac.Sum(nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment