Skip to main content

pycryptodome + CryptoJS-compatible Rijndael for non-standard key sizes

Project description

pycryptojs

pycryptodome + CryptoJS-compatible Rijndael for non-standard key sizes.

Install

pip install -e .

What it does

pycryptojs is a drop-in replacement for pycryptodome (Crypto.*) that adds one extra capability:
AES with non-standard key sizes (e.g. 64 bytes), matching the behavior of CryptoJS when enc.Utf8.parse() produces an oversized key.

Under the hood, CryptoJS follows the Rijndael spec for arbitrary key sizes:

  • 64-byte key → 22 rounds (vs standard AES-256's 14 rounds)
  • pycryptodome rejects these keys; pycryptojs handles them transparently.

Usage

Standard AES — identical to pycryptodome

from pycryptojs.Cipher import AES
from pycryptojs.Util.Padding import pad, unpad

key = b'0123456789abcdef'  # 16, 24, or 32 bytes → pycryptodome handles it
iv  = b'abcdef0123456789'

cipher = AES.new(key, AES.MODE_CBC, iv=iv)
ct = cipher.encrypt(pad(b'hello world', 16))

Non-standard key (e.g. 64 bytes) — Rijndael engine, ECB only

from pycryptojs.Cipher import AES
from pycryptojs.Util.Padding import pad, unpad

key = b'1593cc0b7cd7651ad8a17bc528986046fa3e6e709f6405274b17def26c7faa6r'  # 64 bytes

cipher = AES.new(key, AES.MODE_ECB)
ct = cipher.encrypt(pad(b'0lrtwyvqdaj657hq4t6m', 16))
# decrypt
pt = unpad(cipher.decrypt(ct), 16)

Standalone helpers (base64 in/out, PKCS7 handled internally)

from pycryptojs import rijndael_ecb_encrypt, rijndael_ecb_decrypt

KEY = b'1593cc0b7cd7651ad8a17bc528986046fa3e6e709f6405274b17def26c7faa6r'

enc = rijndael_ecb_encrypt("0lrtwyvqdaj657hq4t6m", KEY)
# → "j7ywbgh7VYbTwxvei9CaRL0rNVQW7zlzeJNd+SRxUjI="

dec = rijndael_ecb_decrypt(enc, KEY)
# → "0lrtwyvqdaj657hq4t6m"

Everything else — same as pycryptodome

from pycryptojs.Hash import SHA256
from pycryptojs.PublicKey import RSA
from pycryptojs.Util.Padding import pad, unpad
from pycryptojs.Random import get_random_bytes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycryptojs-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycryptojs-1.0.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file pycryptojs-1.0.0.tar.gz.

File metadata

  • Download URL: pycryptojs-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pycryptojs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ba04d487c287f8f3bd544e037f041ea710826f8a12c9a1bf5dda4692774e40d0
MD5 0809eb89baec4e05e81855ec7724ff3a
BLAKE2b-256 2a5c270b57649c0d1e087002c8edd8e0868b510f0119fe4335ca5bc279aea994

See more details on using hashes here.

File details

Details for the file pycryptojs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycryptojs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pycryptojs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 713189bab47de2ef018d649b9595fcaa034b9b66316f302ef75c1f641f406575
MD5 8eba4cf3ee6288542bbe26da80bae451
BLAKE2b-256 59db5b2e8a8dfdd71644cd62db221475d6a59d9d92e33db69ae1cae04123101d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page