cryptography
CryptoEncryption & hashing
What is cryptography?
The cryptography library is the leading Python package for cryptographic operations. It provides both high-level recipes (Fernet symmetric encryption) and low-level cryptographic primitives (hashing, key derivation, digital signatures, HMAC) through a clean, safe API designed to prevent common mistakes.
PyRun supports the cryptography library via Pyodide's WebAssembly build. You can hash strings with SHA-256, encrypt and decrypt data using Fernet, and explore key derivation functions — all inside your browser. It's an excellent tool for learning applied cryptography concepts without any local setup.
Code Example
SHA-256 hashing and Fernet symmetric encryption.
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend
from cryptography.fernet import Fernet
# SHA-256 hashing
digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
digest.update(b"Hello, PyRun!")
hash_bytes = digest.finalize()
print("SHA-256:", hash_bytes.hex())
# Fernet symmetric encryption
key = Fernet.generate_key()
f = Fernet(key)
message = b"Secret message from PyRun"
token = f.encrypt(message)
print("\nEncrypted:", token[:40], "...")
decrypted = f.decrypt(token)
print("Decrypted:", decrypted.decode())Why run cryptography in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.