Skip to main content

Обёртки и утилиты для шифрования, подписей и хеширования

Project description

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

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

security_crypto_primitives-0.1.21.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

security_crypto_primitives-0.1.21-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file security_crypto_primitives-0.1.21.tar.gz.

File metadata

File hashes

Hashes for security_crypto_primitives-0.1.21.tar.gz
Algorithm Hash digest
SHA256 12aa132ffbc5078702fc688b29dd5fd76f10e9b928275577953b2ea611b7b327
MD5 daacd6f088055588e118e4bc87531a18
BLAKE2b-256 114fcadcbff26deaef06901dd46c8119a9804bfb9dd7a49dd891f58eb92dba42

See more details on using hashes here.

File details

Details for the file security_crypto_primitives-0.1.21-py3-none-any.whl.

File metadata

File hashes

Hashes for security_crypto_primitives-0.1.21-py3-none-any.whl
Algorithm Hash digest
SHA256 0fbbb629b572a42888a39f8c06d759ff08f09d3c5ddf6df5d552daaea9c58fad
MD5 c9515798d64d7973c33d135c3d5f8a9d
BLAKE2b-256 9d4f731267ef22be816265d113591440662d83cb02b4d4b60d070307b088e354

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