Skip to main content

Python S/MIME Toolkit

Project description

This library implements a S/MIME handler. In this first version, it can only encrypt S/MIME messages using a public RSA key, in AES128-CBC, AES192-CBC or AES256-CBC modes.

The ASN.1 implementation does not depend on pyasn1, as it showed too broken for creating and reading CMS (Cryptographic Message Syntax). Instead, the asn1crypto was used in this project.

This implementation uses pycrypto instead of OpenSSL, so everything is ‘pure python’.


  • Python 2.7 or Python 3.3
  • pycrypto
  • asn1crypto


The code below loads Alice’s public key in PEM format and uses it to encrypt the e-mail in S/MIME format:

import sys
import smime

message = [
    'To: "Alice" <>',
    'From: "Bob" <>',
    'Subject: A message from python',
    'Now you see me.'

with open('alice-public-key.pem', 'rb') as pem:


To: "Alice" <>
From: "Bob" <>
Subject: A message from python
MIME-Version: 1.0
Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name=smime.p7m
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7m


The same can be decrypted using OpenSSL from the command line:

$ openssl smime -decrypt -in smime.p7m -inkey alice-private-key.pem


This software is licensed under the Apache License 2.0. See the LICENSE file in the top distribution directory for the full license text.


This software follows Semantic Versioning

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smime-0.0.2.tar.gz (11.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page