The Easiest Way to Encrypt in Python

Jon McLachlan
2 min readMar 21, 2021

--

Encrypting data is easy, but securing keys is very difficult. You can skim 6 Questions to Ask Before Encryption Data to get a better sense of the responsibilities that come with encrypting data.

Luckily, we can just use Peacemakr to solve these hard problems.

Peacemakr’s E2E-Encryption Python SDK

Peacemakr provides free E2E-Encryption-as-a-Service through an open-source Python SDK. Of course, it supports other languages too. Under the hood, Peacemakr uses a dedicated SaaS to provide centralized configuration management to make your E2E-Encryption simple and fast.

Peacemakr: The Easiest way to Encrypt in Python

#1 Install Dependencies

Since the Peacemakr SDKs are open-source, you may download from the source directly on GitHub. Otherwise, just

$ pip install peacemakr

#2 Get a Peacemakr APIKey

E2E-Encryption requires access to the SaaS. They have a demo APIKey to try it,

export PEACEMAKR_APIKEY=d1Maw58P2xCQ8d0GV15n22SQNI6lYXHzWLCTEvNPHnY=

When you’re ready to use your own keys, just register for a free account at https://peacemakr.io,

#3 Register your Client

Before we encrypt data, we need to register a Peacemakr Client. Registering allows encryption keys to be delivered to your client. Registration requires an APIKey, client name, host, and a persister. For example,

import peacemakr as p
import peacemakr.factory as factory
api_key = "my-api-key-from-step-2-above"
persister = p.InMemoryPersister()
sdk = factory.get_crypto_sdk(api_key=api_key,
client_name="hello world",
peacemakr_hostname="https://api.peacemakr.io",
persister=persister
)
sdk.register()

#4 Finally, Encrypt your Data

Transform your data into a serialized binary format, and use peacemakr to encrypt it. When you’re ready to operate on your data again, decrypt it.

import osrandom_bytes = os.urandom(100)
encrypted_bytes = sdk.encrypt(random_bytes)
...decrypted_bytes = sdk.decrypt(encrypted_bytes)

It’s really that simple. You can read up on what is happening under the hood directly in our open source SDKs, on our website.

--

--

Jon McLachlan

Founder of YSecurity. Ex-Apple, Ex-Robinhood, Ex-PureStorage. Lives in Oakland. Athlete.