'DKIM body hash in python
I'm thinking this should be easy, but I just can't get the body hashsum right for multipart MIME e-mails. My code doesn't work so I just included a simple example of what I'm doing (I'm supplying a file with a full e-mail, headers and all):
#!/usr/bin/env python3
import email
import sys
from base64 import b64encode, b64decode
import hashlib
mail = email.message_from_bytes(open(sys.argv[1], "rb").read())
body = str(mail.get_payload())
canonicalized_body = body.strip().encode() + b"\r\n"
print("SHA256\t:", b64encode(hashlib.sha256(canonicalized_body).digest()))
print("SHA1\t:", b64encode(hashlib.sha1(canonicalized_body).digest()))
Anyone familiar with this? Goy any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
