Simple python functions that provide openssl -aes-256-cbc compatible encrypt/decrypt

The example here shows how to encrypt and decrypt data using python in a way that is fully compatible with openssl aes-256-cbc. It is based on the work that I did in C++ Cipher class that is published on this site. It works for both python-2.7 and python-3.x.

The key idea is based on the way that openssl generates the key and iv data from password as well as the “Salted__” prefix that it uses.

The complete routine can be downloaded here: mycrypt.py.

When you download the script from this section you will be able to perform operations like this.

Basic Routines

The code shown below implements the encrypt and decrypt routines.

The Rest of the Program

The following code shows how to use the previous code to create tool that will encrypt and decrypt in the command line.

3 thoughts on “Simple python functions that provide openssl -aes-256-cbc compatible encrypt/decrypt”

  1. Hi,

    Thanks great, If I want decrypt a message with non ASCII secert, what do I do?

    Is it possible similar -i option for password?

    _regards

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.