Keycove
Keycove is an easy-to-use API authentication library. Create, verify, and securely store API keys.
The key features are:
- Generating api keys: Generates random tokens that can be used as API keys.
- Hashing: Hash API keys to securely store them in your database.
- Encryption / Decryption: Encrypt API keys to securely store keys. Decrypt to view them again.
Generally, encryption / hashing algorithms work with bytes as inputs and outputs to these algorithms. Keycove takes care of converting values to / from bytes so you only need to work with strings.
Generate an api key
generate_token(num_bytes: int = 32) -> str
This function generates a random string that can be uses as an API key.
The num_bytes parameter specifies the number of random bytes to generate before the encoding to a string using Base64 encoding.
Because of this encoding, the length of the resulting string is approximately 1.3x larger than the num_bytes specified.
Parameters:
num_bytes (int): The number of random bytes to generate before encoding. Default is 32.
Returns:
str: A random string.
Example:
from keycove import generate_token
generate_token(num_bytes=16)
>>> '4LYAecdQvqH_W2OABLsZzV-6-zAAkt23'
Generate a secret key
generate_secret_key() -> str
This function generates a secret key that is compatible with the encrypt and decrypt functions.
The generated secret key is suitable for the Fernet symmetric encryption algorithm, which this library uses for encryption.
Returns:
str: A secret key that can be used with the encrypt and decrypt functions.
Example:
from keycove import generate_secret_key
generate_secret_key()
>>> 'gAAAAABgTD0yR3O4hV7Kb7PZ6N4iZA3uJNeL3_ZI2QmGJHbLZUj4Cy5B2Pgh4lX3JNLUZ4Q8OvJZ8OZyXUYd8l4XQJZIV64nJA=='
Encrypt
encrypt(value_to_encrypt: str, secret_key: str) -> str
This function encrypts a given string using a provided secret key.
Use keycove.generate_secret_key() to generate this secret key.
This secret key is suitable for the Fernet symmetric encryption algorithm, which is used for encryption.
Parameters:
value_to_encrypt (str): The string to encrypt.
secret_key (str): The secret key to use for encryption.
Use keycove.generate_secret_key() to generate this secret key.
Returns:
str: The encrypted string.
Raises:
TypeError: If value_to_encrypt is not a string.
TypeError: If secret_key is not a string.
ValueError: If secret_key is incorrect.
Example:
from keycove import encrypt, generate_secret_key
secret_key = generate_secret_key()
encrypt(value_to_encrypt="Hello, World!", secret_key=secret_key)
>>> 'gAAAAABgTD0yR3O4hV7Kb7PZ6N4iZA3uJNeL3_ZI2QmGJHbLZUj4Cy5B2Pgh4lX3JNLUZ4Q8OvJZ8OZyXUYd8l4XQJZIV64nJA=='
Decrypt
decrypt(encrypted_value: str, secret_key: str) -> str
This function decrypts a given encrypted string using a provided secret key.
The same secret key that was used to encrypt the encrypted_value should be used to decrypt it.
Parameters:
encrypted_value (str): The encrypted string to decrypt.
secret_key (str): The secret key to use for decryption.
Returns:
str: The decrypted string.
Raises:
TypeError: If encrypted_value is not a string.
TypeError: If secret_key is not a string.
ValueError: If secret_key is incorrect.
Example:
from keycove import decrypt, encrypt, generate_secret_key
secret_key = generate_secret_key()
encrypted_value = encrypt(value_to_encrypt="Hello, World!", secret_key=secret_key)
decrypt(encrypted_value=encrypted_value, secret_key=secret_key)
>>> 'Hello, World!'
Hash
hash(value_to_hash: str) -> str
This function hashes a given string using the SHA256 algorithm.
Parameters:
value_to_hash (str): The string to hash.
Returns:
str: The hashed string.
Example:
from keycove import hash
hash(value_to_hash="Hello, World!")
>>> '2ef7bde608ce5404e97d5f042f95f89f1c232871'
Metadata
Release files for keycove 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| keycove-0.3.5.tar.gz | 4.3 kB | Without provenance | Details for keycove-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| keycove-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for keycove-0.3.5-py3-none-any.whl |
Total release size: 10.0 kB
Release files / keycove-0.3.5.tar.gz
| Download URL | keycove-0.3.5.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b0b70cfeec7fb4b0884cb89b96a5d24e54d21a7b3757ea7322213a3e5da5395
|
|
BLAKE2b-256 checksum How to use checksums |
959fb7210f8a306179fef0239ad73b6da530b3f9d8a49ebd9999f1032e96c25a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.1
|
Release files / keycove-0.3.5-py3-none-any.whl
| Download URL | keycove-0.3.5-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe55719cc9363b4a5bfe180188a714e05e94f5a0cca79b1b544de954b79c70c5
|
|
BLAKE2b-256 checksum How to use checksums |
3d8229085598c6219b50283dc02052832722665a943ff117f6344f81ae19581c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.1
|
Security for keycove 0.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.