Skip to main content

Universal cryptographic toolkit — password hashing, AES-256-GCM, SHA3, BLAKE2, PBKDF2, scrypt, secure tokens. Zero external dependencies.

Project description

crypto-gate (Python)

Universal Cryptographic Toolkit — by Analytics With Harry · Squid Consultancy Group Limited

PyPI version License: MIT Python ≥3.7


Why crypto-gate?

One package. Every crypto primitive you need. Minimal dependencies.

crypto-gate wraps Python's built-in hashlib, hmac, and secrets modules into a clean, consistent API.

  • Password Hashingscrypt (memory-hard) + PBKDF2-SHA512
  • Symmetric EncryptionAES-256-GCM authenticated encryption (via cryptography)
  • HashingSHA-256/384/512, SHA3-256/512, BLAKE2b/BLAKE2s, MD5
  • HMACHMAC-SHA256/SHA512
  • Key Derivationscrypt, PBKDF2
  • Secure Tokens — UUID v4, OTP, API keys, recovery keys
  • Timing-safe comparison

Installation

pip install crypto-gate

Requires Python ≥ 3.7.


Quick Start

from crypto_gate import PasswordHasher, Hasher, TokenGenerator

# Hash a password
hash = PasswordHasher.hash("my-secret-password")
print(hash)  # $cgscrypt$v1$32768$8$1$<salt>$<hash>

# Verify
ok = PasswordHasher.verify("my-secret-password", hash)
print(ok)  # True

# SHA-256
print(Hasher.sha256("hello world"))

# UUID
print(TokenGenerator.uuid())

# OTP
print(TokenGenerator.otp(6))  # 847291

API Reference

PasswordHasher

# scrypt (memory-hard, NIST-recommended)
hash = PasswordHasher.hash("password", n=32768, r=8, p=1, keylen=64)
ok   = PasswordHasher.verify("password", hash)

# PBKDF2-SHA512
hash = PasswordHasher.hash_pbkdf2("password", iterations=310000, keylen=64, digest="sha512")
ok   = PasswordHasher.verify_pbkdf2("password", hash)

# Strength analysis
result = PasswordHasher.analyze_strength("P@ssw0rd!")
# {"score": 7, "strength": "Very Strong", "suggestions": []}

AESCipher

from crypto_gate import AESCipher

key = AESCipher.generate_key()
enc = AESCipher.encrypt("sensitive data", key)
dec = AESCipher.decrypt(enc, key)

# Key from passphrase
kd = AESCipher.derive_key("my-passphrase")
enc = AESCipher.encrypt("data", kd["key"])

Hasher

from crypto_gate import Hasher

Hasher.sha256("data")          # hex
Hasher.sha512("data")          # hex
Hasher.sha3_256("data")        # hex
Hasher.sha3_512("data")        # hex
Hasher.blake2b("data")         # hex (64-byte digest)
Hasher.blake2s("data")         # hex (32-byte digest)
Hasher.md5("data")             # hex (legacy only)

# HMAC
Hasher.hmac_sha256("msg", "key")
Hasher.hmac_sha512("msg", "key")
Hasher.hmac("msg", "key", algorithm="sha384")

# Encodings
Hasher.sha256("data", encoding="base64")
Hasher.sha256("data", encoding="bytes")    # returns bytes

# Timing-safe compare
Hasher.compare(hash_a, hash_b)

KeyDeriver

from crypto_gate import KeyDeriver

r = KeyDeriver.scrypt("password", salt=None, keylen=64, n=32768, r=8, p=1)
# r = {"key": "hex...", "salt": "hex..."}

r = KeyDeriver.pbkdf2("password", salt=None, keylen=64, iterations=310000, digest="sha512")

TokenGenerator

from crypto_gate import TokenGenerator

TokenGenerator.random(32, "hex")         # 64-char hex token
TokenGenerator.random(32, "base64url")   # URL-safe base64

TokenGenerator.uuid()                    # "550e8400-e29b-41d4-a716-..."
TokenGenerator.otp(6)                    # "847291"
TokenGenerator.api_key("live")           # "cg_live_3f7a8b9c..."
TokenGenerator.recovery_key(4)           # "A3F2-88BC-4E19-DD73"
TokenGenerator.bytes(16)                 # b'\x3a\x7f...' — raw bytes
TokenGenerator.random_int(1, 100)        # secure random int in [1, 100]

Encoder

from crypto_gate import Encoder

Encoder.to_base64("hello")          # 'aGVsbG8='
Encoder.from_base64('aGVsbG8=')     # 'hello'
Encoder.to_base64url("hello world")
Encoder.from_base64url(s)
Encoder.to_hex("hello")             # '68656c6c6f'
Encoder.from_hex('68656c6c6f')      # 'hello'
Encoder.bytes_to_hex(b"data")
Encoder.hex_to_bytes("646174")

timing_safe_equal

from crypto_gate import timing_safe_equal

timing_safe_equal(hash_a, hash_b)  # bool — constant-time comparison

Security Notes

  • scrypt vs bcrypt: scrypt is memory-hard and more resistant to GPU/ASIC attacks. Recommended for new systems.
  • AES-256-GCM: Authenticated encryption provides both confidentiality and integrity.
  • Timing-safe comparison: Always use timing_safe_equal or Hasher.compare for secret comparison.

Node.js Package

A companion Node.js implementation is available on npm with the same API structure, using only the built-in crypto module.

npm install crypto-gate

License

MIT © Analytics With Harry - Squid Consultancy Group Limited

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

crypto_gate-1.1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

crypto_gate-1.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file crypto_gate-1.1.1.tar.gz.

File metadata

  • Download URL: crypto_gate-1.1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for crypto_gate-1.1.1.tar.gz
Algorithm Hash digest
SHA256 a87596808dbde13b4e35abb99769b72e46a7b414ac99bf5844adf2550bba0e7e
MD5 b60f567b6c095f4871653168555325f3
BLAKE2b-256 6cb4fc43e4b46e24426e7c5ddf8a9f70fcd12520b69e0be583beb0840932eaa6

See more details on using hashes here.

File details

Details for the file crypto_gate-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: crypto_gate-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for crypto_gate-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 400537476e9123d9cf20ec7f7ddff7300ce7821de767363d018e18abe0e47924
MD5 0c813b3ef91811d7892587ced0198c2f
BLAKE2b-256 89e2ec59c10dcad809eb4669bfdbd3aefd280fc64aad62a53c2e7bc4d17ca12a

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