Last active
June 3, 2022 10:39
-
-
Save tanelmae/2ba36e117558a46461bb89cd287487bd to your computer and use it in GitHub Desktop.
Example how to generate AWS SES password from AWS secret key
This file contains 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
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