Easy Python Cryptography
14th April 2003
Via Garth Kidd’s Python cryptography roundup, ezPyCrypto is a cryptography API so simple even I can use it. Unfortunately the example code is only available in the download archive (not on the web site) but here’s an overview of how it works:
import ezPyCrypto
# Generate a 512 bit key
key = ezPyCrypto.key(512)
text = 'This will be encrypted'
# Encrypt the string
encrypted = key.encString(text)
print encrypted
# Unencrypt the string
decrypted = key.decString(encrypted)
print decrypted
# Export the public key
public = key.exportKey()
# This can now be saved or distributed
# Export the private key
private = key.exportKeyPrivate()
# This can now be saved somewhere safe
# Encrypting using an already generated public key:
key = ezPyCrypto.key()
key.importKey(public)
encrypted = key.encString(text)
# Decrypting using an already generated private key:
key = ezPyCrypto.key()
key.importKey(private)
decrypted = key.decString(text)
That’s pretty much it. The class also has support for passphrases which can be used to add an extra layer of protection to a private key, as well as methods to handle crypotgraphic signing and verification.
ezPyCrypto is an easy to use wrapper for the excellent PyCrypto module, and includes PyCrypto (and a handy Windows installer) in the distribution.
More recent articles
- Talking Large Language Models with Rooftop Ruby - 29th September 2023
- Weeknotes: Embeddings, more embeddings and Datasette Cloud - 17th September 2023
- Build an image search engine with llm-clip, chat with models with llm chat - 12th September 2023
- LLM now provides tools for working with embeddings - 4th September 2023
- Datasette 1.0a4 and 1.0a5, plus weeknotes - 30th August 2023
- Making Large Language Models work for you - 27th August 2023
- Datasette Cloud, Datasette 1.0a3, llm-mlc and more - 16th August 2023
- How I make annotated presentations - 6th August 2023
- Weeknotes: Plugins for LLM, sqlite-utils and Datasette - 5th August 2023
- Catching up on the weird world of LLMs - 3rd August 2023