cryptography

Crypto

Encryption & hashing

Try cryptography in PyRun

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.

Cryptography: Hash & Encrypt
Try in Editor
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
Open editor with cryptography example

Related Packages