A library to generate secure random secret keys for Flask apps.
Project description
FlaskSecureKeyGen
FlaskSecureKeyGen is a Python library designed to generate secure, random secret keys for Flask applications. It ensures that your Flask app's secret keys are cryptographically strong and suitable for production use.
Installation
You can install FlaskSecureKeyGen using pip:
pip install FlaskSecureKeyGen
Usage
1. Generating a Secret Key
The main functionality of this library is to generate secure secret keys. You can use the generate_secret_key function from the keygen module.
from flask_secure_keygen import generate_secret_key
# Generate a 64-character secret key
secret_key = generate_secret_key(64)
print(secret_key)
Parameters:
length: The length of the secret key (default is 64). Must be at least 32 characters for security.
Example Output:
3a1f8e4d7c9b2a5f6e8c9d0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0
2. Using Utility Functions
The library also provides utility functions in the utils module to help validate key lengths.
from flask_secure_keygen.utils import validate_key_length
# Check if a key length is valid
is_valid = validate_key_length(40)
print(is_valid) # Output: True
Parameters:
length: The desired key length to validate.
Returns:
Trueif the length is valid (i.e., 32 or more characters).Falseotherwise.
3. Integrating with Flask
You can use the generated secret key directly in your Flask application.
from flask import Flask
from flask_secure_keygen import generate_secret_key
app = Flask(__name__)
# Generate and set a secure secret key for the Flask app
app.secret_key = generate_secret_key(64)
@app.route('/')
def home():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)
Why Use FlaskSecureKeyGen?
- Secure: Uses Python's
secretsmodule to generate cryptographically strong random keys. - Simple: Just one function to generate keys of any length (minimum 32 characters).
- Customizable: You can specify the length of the key as per your requirements.
- Utility Functions: Additional utility functions to validate key lengths.
Modules Overview
1. keygen Module
This module contains the main functionality for generating secret keys.
generate_secret_key(length=64):Generates a secure random secret key of the specified length.
2. utils Module
This module provides utility functions for additional functionality.
validate_key_length(length):Validates if the provided key length is secure (at least 32 characters).
Contributing
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue on the GitHub repository.
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Made with Love by Ch. Abdul Wahab
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 flasksecurekeygen-0.1.0.tar.gz.
File metadata
- Download URL: flasksecurekeygen-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58e3bd8b3228e1dee03131cf6ab5fb895facf49e4766e5f5d6945247a1b97770
|
|
| MD5 |
29dff61228b1f3c0278203d46db97c32
|
|
| BLAKE2b-256 |
dfbf28aefaedc6ca8173a035fdc3184ab7e16a1f0b38c97c7870b9fbb2b1d656
|
File details
Details for the file FlaskSecureKeyGen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: FlaskSecureKeyGen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1d45943d10d57b9fb20fb21c6fdd740ac38837e07b2f5b7304b78212b5e83ae
|
|
| MD5 |
fc3cef56fd8fd36f65199cbe30bb53ce
|
|
| BLAKE2b-256 |
2372c0b192fdcb93fe5cf95d5b2b987a9bb882c815cbd4e8ff4b23b3c8ba5409
|