Skip to content

Instantly share code, notes, and snippets.

@adamchainz
Created November 23, 2016 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamchainz/a967be11065c6037a4f8e1b40774bbca to your computer and use it in GitHub Desktop.
Save adamchainz/a967be11065c6037a4f8e1b40774bbca to your computer and use it in GitHub Desktop.
SES credentials hash
"""
Implements the algorithm at https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
"""
import hmac
import hashlib
import base64
def ses_hash(secret_access_key):
message = "SendRawEmail"
version = 0x02
signature = hmac.new(
key=secret_access_key,
msg=message,
digestmod=hashlib.sha256,
).digest()
signature_and_ver = b'\x02' + signature
password = base64.b64encode(signature_and_ver)
return password
@kthhrv
Copy link

kthhrv commented Sep 1, 2021

A python version has since been added to the amazon doc https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html#python

@adamchainz
Copy link
Author

Good to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment