Skip to content

Instantly share code, notes, and snippets.

@w3iBStime
Last active August 10, 2018 04:57
Show Gist options
  • Save w3iBStime/a26bd670bf7f98675674 to your computer and use it in GitHub Desktop.
Save w3iBStime/a26bd670bf7f98675674 to your computer and use it in GitHub Desktop.
Python script to derive AWS SES SMTP passwords from IAM access secret keys using HMAC, SHA256 and Base64 per http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
import base64
import hmac
import hashlib
secret = "_____" # replace with the secret key to be hashed
message = "SendRawEmail"
sig_bytes = bytearray(b'\x02') # init with version
theHmac = hmac.new(secret.encode("ASCII"), message.encode("ASCII"), hashlib.sha256)
the_hmac_hexdigest = theHmac.hexdigest()
sig_bytes.extend(bytearray.fromhex(the_hmac_hexdigest))
print(base64.b64encode(sig_bytes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment