Skip to main content

crypto_utils

Описание

crypto_utils — это простая и удобная Python-библиотека с обёртками над криптографическими алгоритмами на базе cryptography.

Основные возможности:

  • encrypt.py: AES-GCM и ChaCha20-Poly1305 шифрование/дешифрование
  • sign.py: RSA-PSS и ECDSA подпись и верификация
  • hash.py: функции хеширования SHA-256, SHA-512, SHA3-256, SHA3-512
  • kdf.py: PBKDF2-HMAC и scrypt для безопасного вывода ключей

Установка

pip install crypto_utils

Быстрый старт

Шифрование/дешифрование (AES-GCM)

from crypto_utils.encrypt import encrypt_aes_gcm, decrypt_aes_gcm

key = b"\x00" * 32
nonce, ct = encrypt_aes_gcm(key, b"секретные данные", b"aad")
plaintext = decrypt_aes_gcm(key, nonce, ct, b"aad")
print(plaintext)  # b"секретные данные"

Подпись/верификация (RSA)

from crypto_utils.sign import (
    generate_rsa_private_key, rsa_public_key_to_pem,
    sign_rsa, verify_rsa
)

priv = generate_rsa_private_key()
pub = priv.public_key()
sig = sign_rsa(priv, b"сообщение")
print(verify_rsa(pub, b"сообщение", sig))  # True

Хеширование (SHA3-256)

from crypto_utils.hash import hash_sha3_256

digest = hash_sha3_256(b"данные для хеша")
print(digest.hex())

Производные функции ключей (PBKDF2)

from crypto_utils.kdf import derive_pbkdf2

key, salt = derive_pbkdf2(b"пароль", iterations=200_000, length=64)
print(key.hex(), salt.hex())

Тесты

pytest --maxfail=1 --disable-warnings -q

Лицензия

MIT License


Description

crypto_utils is a lightweight Python library wrapping cryptographic primitives (built on cryptography).

Features:

  • encrypt.py: AES-GCM and ChaCha20-Poly1305 encryption/decryption
  • sign.py: RSA-PSS and ECDSA signing & verification
  • hash.py: SHA-256, SHA-512, SHA3-256, SHA3-512 hashing functions
  • kdf.py: PBKDF2-HMAC and scrypt key derivation functions

Installation

pip install crypto_utils

Quick Start

Encryption/Decryption (AES-GCM)

from crypto_utils.encrypt import encrypt_aes_gcm, decrypt_aes_gcm

key = b"\x00" * 32
nonce, ct = encrypt_aes_gcm(key, b"secret data", b"aad")
plaintext = decrypt_aes_gcm(key, nonce, ct, b"aad")
print(plaintext)  # b"secret data"

Signing/Verification (RSA)

from crypto_utils.sign import (
    generate_rsa_private_key, rsa_public_key_to_pem,
    sign_rsa, verify_rsa
)

priv = generate_rsa_private_key()
pub = priv.public_key()
sig = sign_rsa(priv, b"message")
print(verify_rsa(pub, b"message", sig))  # True

Hashing (SHA3-256)

from crypto_utils.hash import hash_sha3_256

digest = hash_sha3_256(b"data to hash")
print(digest.hex())

Key Derivation (PBKDF2)

from crypto_utils.kdf import derive_pbkdf2

key, salt = derive_pbkdf2(b"password", iterations=200_000, length=64)
print(key.hex(), salt.hex())

Running tests

pytest --maxfail=1 --disable-warnings -q

License

MIT License

Metadata

Release files for security-crypto-primitives 0.1.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for security-crypto-primitives 0.1.21
File Size Uploaded
security_crypto_primitives-0.1.21.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for security-crypto-primitives 0.1.21
File Interpreter ABI Platform
security_crypto_primitives-0.1.21-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / security_crypto_primitives-0.1.21.tar.gz

Download URL security_crypto_primitives-0.1.21.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
12aa132ffbc5078702fc688b29dd5fd76f10e9b928275577953b2ea611b7b327
BLAKE2b-256 checksum
How to use checksums
114fcadcbff26deaef06901dd46c8119a9804bfb9dd7a49dd891f58eb92dba42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / security_crypto_primitives-0.1.21-py3-none-any.whl

Download URL security_crypto_primitives-0.1.21-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fbbb629b572a42888a39f8c06d759ff08f09d3c5ddf6df5d552daaea9c58fad
BLAKE2b-256 checksum
How to use checksums
9d4f731267ef22be816265d113591440662d83cb02b4d4b60d070307b088e354
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.21 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page