Simple cryptography library
Project description
Simple cryptography library
> pip install kry
BEWARE: This library (currently) is not optimized and is probably vulnerable to side channel attacks.
Sections
1. Introduction
2. API reference
2.1 Hash functions
3. Examples
4. Changelog
1. Introduction
Features
* Simple: one operation (e.g. SHA-256 hashing) is one function (e.g. kry.sha256("hello")).
* Data streaming using generator.
* Save/Restore state.
* Save: an empty yield returns the current state (as bytes).
* Restore: initial_state parameter.
2. API reference
The library (currently) only implements hash functions (see section 2.1).
kry.__all__ is a tuple containing all public names in the library.
2.1 Hash functions
md2, md4, md5, ripemd128, ripemd160, ripemd256, ripemd320, sha1, sha224, sha256, sha384, sha512,
sha512_224, sha512_256, sm3.
Return: Bytes.
Parameters: (data, initial_state=None)
* data: Data to be hashed. Must be string, bytes, iterable (of strings and/or bytes), .read()-able (of
strings and/or bytes) or pathlib.Path (to a file). Strings will be UTF-8-encoded.
* initial_state: Must be bytes or None. If data is a generator, an empty yield returns the current
state (as bytes).
3. Examples
import kry
# string
kry.sha256("") # b"\xda9\xa3\xee^kK\r2U\xbf...
kry.sha256("").hex() # "da39a3ee5e6b4b0d3255bf...
kry.sha256("abc")
# bytes
kry.sha256(b"\x00\x01\x02-hello\x03")
kry.sha256(kry.sha256("double hash"))
def gen(): # Python generator may be used for streaming data
yield "Red"
yield "Green"
# An empty yield returns the current state (as bytes)
state = yield
print(state) # Print SHA-256 state after "RedGreen" has been processed
kry.sha256("Yellow", initial_state=state) # Equivalent to kry.sha256("RedGreenYellow")
yield "Blue"
# iterable
kry.sha256(gen()) # Equivalent to kry.sha256("RedGreenBlue")
kry.sha256(["Red", b"Green", "Blue"]) # Equivalent to kry.sha256("RedGreenBlue")
kry.sha256(((i*i).to_bytes(1) for i in range(4))) # Equivalent to kry.sha256(b"\x00\x01\x04\x09")
# .read()-able
kry.sha256(open("red.txt"))
with open("blue.txt") as file:
kry.sha256(file)
kry.sha256(open("cat.png", "rb"))
import io
kry.sha256(io.BytesIO(b"12345"))
# pathlib.Path
from pathlib import Path
kry.sha256(Path("colors.txt"))
kry.sha256(Path("dog.gif"))
4. Changelog
1.0.0
* Add md2, md4, md5, ripemd128, ripemd160, ripemd256, ripemd320, sha1, sha224, sha256, sha384,
sha512, sha512_224, sha512_256, sm3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kry-1.0.0.tar.gz.
File metadata
- Download URL: kry-1.0.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd644fc466ac6d45fc8e99f1c52bdafb788e12442e114d3371aa478509abb551
|
|
| MD5 |
95161b396b0e45baf5033fc4e4e5080c
|
|
| BLAKE2b-256 |
53c583969e74bb7092d10cde14d41003b93630cf1f25fcb44975405e7ae70883
|
Provenance
The following attestation bundles were made for kry-1.0.0.tar.gz:
Publisher:
pypi-publish.yml on 0b-0/kry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kry-1.0.0.tar.gz -
Subject digest:
dd644fc466ac6d45fc8e99f1c52bdafb788e12442e114d3371aa478509abb551 - Sigstore transparency entry: 264415915
- Sigstore integration time:
-
Permalink:
0b-0/kry@c96b7867b8bed38797b3f082f85a966ae19414a0 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/0b-0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@c96b7867b8bed38797b3f082f85a966ae19414a0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kry-1.0.0-py3-none-any.whl.
File metadata
- Download URL: kry-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cfb849cc9df7a367885ef09a31cda16a07119501e266ae8c78ac8af027875d6
|
|
| MD5 |
a68c7a8c9aaf595ca4a0ccfd0bb58fa2
|
|
| BLAKE2b-256 |
ddff592a5580f1598c13c0e840e815cff0243d6041bfe3f25751292a714ce1df
|
Provenance
The following attestation bundles were made for kry-1.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on 0b-0/kry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kry-1.0.0-py3-none-any.whl -
Subject digest:
3cfb849cc9df7a367885ef09a31cda16a07119501e266ae8c78ac8af027875d6 - Sigstore transparency entry: 264415918
- Sigstore integration time:
-
Permalink:
0b-0/kry@c96b7867b8bed38797b3f082f85a966ae19414a0 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/0b-0
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@c96b7867b8bed38797b3f082f85a966ae19414a0 -
Trigger Event:
push
-
Statement type: