pyaescbc 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyaescbc might be problematic. Click here for more details.
- pyaescbc-0.1.0/.bumpver.toml +9 -0
- pyaescbc-0.1.0/.github/workflows/sphinx.yml +40 -0
- pyaescbc-0.1.0/.gitignore +26 -0
- pyaescbc-0.1.0/.gitlab-ci.yml +12 -0
- pyaescbc-0.1.0/LICENSE +13 -0
- pyaescbc-0.1.0/Makefile +60 -0
- pyaescbc-0.1.0/PKG-INFO +114 -0
- pyaescbc-0.1.0/README.md +76 -0
- pyaescbc-0.1.0/docs/source/api.rst +9 -0
- pyaescbc-0.1.0/docs/source/conf.py +57 -0
- pyaescbc-0.1.0/docs/source/index.rst +57 -0
- pyaescbc-0.1.0/docs/source/installation.rst +31 -0
- pyaescbc-0.1.0/docs/source/usage.rst +56 -0
- pyaescbc-0.1.0/examples/encrypt.py +18 -0
- pyaescbc-0.1.0/pyaescbc/__init__.py +64 -0
- pyaescbc-0.1.0/pyaescbc/__main__.py +40 -0
- pyaescbc-0.1.0/pyaescbc/__version__.py +1 -0
- pyaescbc-0.1.0/pyaescbc/auth_error.py +50 -0
- pyaescbc-0.1.0/pyaescbc/check_hmac.py +56 -0
- pyaescbc-0.1.0/pyaescbc/cleardata_to_encrypted_bundle.py +124 -0
- pyaescbc-0.1.0/pyaescbc/create_encrypted_bundle.py +70 -0
- pyaescbc-0.1.0/pyaescbc/create_hmac.py +81 -0
- pyaescbc-0.1.0/pyaescbc/decrypt_AES_CBC.py +78 -0
- pyaescbc-0.1.0/pyaescbc/delete_bytearray.py +49 -0
- pyaescbc-0.1.0/pyaescbc/derive_key.py +82 -0
- pyaescbc-0.1.0/pyaescbc/encrypt_AES_CBC.py +76 -0
- pyaescbc-0.1.0/pyaescbc/encrypted_bundle_to_cleardata.py +131 -0
- pyaescbc-0.1.0/pyaescbc/extract_cryptography_components.py +55 -0
- pyaescbc-0.1.0/pyaescbc/generate_pin_iterations.py +109 -0
- pyaescbc-0.1.0/pyaescbc/generate_random_iterations.py +83 -0
- pyaescbc-0.1.0/pyaescbc/random_bytearray.py +44 -0
- pyaescbc-0.1.0/pyaescbc/random_iv.py +26 -0
- pyaescbc-0.1.0/pyaescbc/random_salt.py +26 -0
- pyaescbc-0.1.0/pyaescbc/resources/__init__.py +0 -0
- pyaescbc-0.1.0/pyaescbc/resources/decrypt.png +0 -0
- pyaescbc-0.1.0/pyaescbc/resources/encrypt.png +0 -0
- pyaescbc-0.1.0/pyaescbc.egg-info/PKG-INFO +114 -0
- pyaescbc-0.1.0/pyaescbc.egg-info/SOURCES.txt +43 -0
- pyaescbc-0.1.0/pyaescbc.egg-info/dependency_links.txt +1 -0
- pyaescbc-0.1.0/pyaescbc.egg-info/requires.txt +9 -0
- pyaescbc-0.1.0/pyaescbc.egg-info/top_level.txt +1 -0
- pyaescbc-0.1.0/pyproject.toml +55 -0
- pyaescbc-0.1.0/setup.cfg +4 -0
- pyaescbc-0.1.0/tests/__init__.py +0 -0
- pyaescbc-0.1.0/tests/test_encryption.py +26 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Deploy Documentation to GitHub Pages
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
pages: write
|
|
11
|
+
id-token: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
deploy:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout the repository
|
|
19
|
+
uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@v4
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.9"
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: |
|
|
28
|
+
pip install -r requirements.txt
|
|
29
|
+
pip install sphinx pydata-sphinx-theme
|
|
30
|
+
|
|
31
|
+
- name: Build documentation
|
|
32
|
+
run: sphinx-build -b html docs/source/ public/
|
|
33
|
+
|
|
34
|
+
- name: Deploy to GitHub Pages
|
|
35
|
+
uses: JamesIves/github-pages-deploy-action@v4
|
|
36
|
+
|
|
37
|
+
with:
|
|
38
|
+
branch: gh-pages
|
|
39
|
+
folder: public
|
|
40
|
+
clean: true
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Python cache files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
|
|
7
|
+
# Virtual environment
|
|
8
|
+
env/
|
|
9
|
+
venv/
|
|
10
|
+
*_pyvenv.cfg
|
|
11
|
+
*.egg-info/
|
|
12
|
+
|
|
13
|
+
# Laboratory
|
|
14
|
+
laboratory/
|
|
15
|
+
|
|
16
|
+
# Sphinx documentation
|
|
17
|
+
build/
|
|
18
|
+
|
|
19
|
+
# Jupyter Notebook checkpoints
|
|
20
|
+
.ipynb_checkpoints/
|
|
21
|
+
|
|
22
|
+
# IDE files
|
|
23
|
+
.idea/
|
|
24
|
+
.vscode/
|
|
25
|
+
*.sublime-project
|
|
26
|
+
*.sublime-workspace
|
pyaescbc-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Artezaru
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
pyaescbc-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# 0. Setting default
|
|
2
|
+
SPHINXOPTS ?=
|
|
3
|
+
SPHINXBUILD ?= sphinx-build
|
|
4
|
+
SOURCEDIR = docs/source
|
|
5
|
+
BUILDDIR = docs/build
|
|
6
|
+
|
|
7
|
+
message ?= Default-commit-message
|
|
8
|
+
level ?= patch
|
|
9
|
+
|
|
10
|
+
# 1. Default help command to list available Sphinx options
|
|
11
|
+
help:
|
|
12
|
+
@echo "Available commands:"
|
|
13
|
+
@echo " help - Show this help message"
|
|
14
|
+
@echo " html - Generate HTML documentation with sphinx-build (output at docs/build/html/)"
|
|
15
|
+
@echo " latexpdf - Generate LaTeX PDF documentation with Sphinx sphinx-build (output at docs/build/latex/)"
|
|
16
|
+
@echo " clean - Clean the documentation build directory docs/build/"
|
|
17
|
+
@echo " bump - Update the version of the package (default: patch, use level=major/minor/patch)"
|
|
18
|
+
@echo " git - Commit and push changes to master (use message='Your commit message')"
|
|
19
|
+
@echo " app - Build the application with PyInstaller (output at dist/)"
|
|
20
|
+
@echo " test - Run the tests of the package with pytest"
|
|
21
|
+
|
|
22
|
+
.PHONY: help Makefile
|
|
23
|
+
|
|
24
|
+
# 2. Generate HTML documentation
|
|
25
|
+
html:
|
|
26
|
+
$(SPHINXBUILD) -b html $(SOURCEDIR) $(BUILDDIR)/html
|
|
27
|
+
|
|
28
|
+
# 3. Generate LaTeX PDF documentation
|
|
29
|
+
latexpdf:
|
|
30
|
+
$(SPHINXBUILD) -b latex $(SOURCEDIR) $(BUILDDIR)/latex
|
|
31
|
+
cd $(BUILDDIR)/latex && pdflatex pyaescbc.tex && pdflatex pyaescbc.tex
|
|
32
|
+
|
|
33
|
+
# 4. Clean the documentation
|
|
34
|
+
clean:
|
|
35
|
+
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O);
|
|
36
|
+
cd $(BUILDDIR); mkdir -p html; mkdir -p latex
|
|
37
|
+
|
|
38
|
+
# 5. Update the version of the package
|
|
39
|
+
bump:
|
|
40
|
+
bumpver update --$(level) --no-fetch
|
|
41
|
+
|
|
42
|
+
# 6. Git Push origin Master
|
|
43
|
+
git:
|
|
44
|
+
git checkout master
|
|
45
|
+
git add -A .
|
|
46
|
+
git commit -m "$(message)"
|
|
47
|
+
git push origin master
|
|
48
|
+
|
|
49
|
+
# 7. Create the application
|
|
50
|
+
app:
|
|
51
|
+
echo "from pyaescbc.__main__ import __main_gui__" > run_gui.py
|
|
52
|
+
echo "__main_gui__()" >> run_gui.py
|
|
53
|
+
pyinstaller --name pyaescbc --onefile --windowed run_gui.py
|
|
54
|
+
rm run_gui.py
|
|
55
|
+
rm -rf build
|
|
56
|
+
rm run_gui.spec
|
|
57
|
+
|
|
58
|
+
# 8. Tests the package
|
|
59
|
+
test:
|
|
60
|
+
pytest tests
|
pyaescbc-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyaescbc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AES-CBC encryption tools based on crytography package.
|
|
5
|
+
Author-email: Artezaru <artezaru.github@proton.me>
|
|
6
|
+
License: Copyright 2025 Artezaru
|
|
7
|
+
|
|
8
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License.
|
|
10
|
+
You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
See the License for the specific language governing permissions and
|
|
18
|
+
limitations under the License.
|
|
19
|
+
Project-URL: Homepage, https://github.com/Artezaru/pyaescbc
|
|
20
|
+
Project-URL: Documentation, https://Artezaru.github.io/pyaescbc
|
|
21
|
+
Project-URL: Source, https://github.com/Artezaru/pyaescbc
|
|
22
|
+
Project-URL: Tracker, https://github.com/Artezaru/pyaescbc/issues
|
|
23
|
+
Classifier: Programming Language :: Python :: 3
|
|
24
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
25
|
+
Classifier: Operating System :: OS Independent
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: cryptography>=39.0.1
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
32
|
+
Requires-Dist: pydata-sphinx-theme; extra == "dev"
|
|
33
|
+
Requires-Dist: numpydoc; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
36
|
+
Requires-Dist: bumpver; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# pyaescbc
|
|
40
|
+
|
|
41
|
+
## Description
|
|
42
|
+
|
|
43
|
+
AES-CBC encryption tools based on crytography package !
|
|
44
|
+
|
|
45
|
+
The package `pyaescbc` provides functions to encrypt and decrypt data using the AES-CBC encryption mode. The package is written in Python and uses the `cryptography` library for the AES encryption and decryption. The package also provides functions to generate a derived key from a password and a pin, and to create an HMAC value from the derived key, IV, and ciphertext. The package is designed to be easy to use and secure, and it is suitable for encrypting sensitive data.
|
|
46
|
+
|
|
47
|
+
General usage of the package includes:
|
|
48
|
+
|
|
49
|
+
``` python
|
|
50
|
+
import pyaescbc
|
|
51
|
+
|
|
52
|
+
# Encryption
|
|
53
|
+
cleardata = bytearray("Hello, World!", 'utf-8')
|
|
54
|
+
pin = bytearray("1234", 'utf-8')
|
|
55
|
+
password = bytearray("password", 'utf-8')
|
|
56
|
+
iterations = pyaescbc.generate_pin_iterations(pin, delete_keys=True)
|
|
57
|
+
authdata = bytearray("user=toto", 'utf-8') # Optional authentication data (can be None)
|
|
58
|
+
encrypted_bundle = pyaescbc.encrypt(cleardata, password, iterations, authdata=authdata, delete_keys=True)
|
|
59
|
+
|
|
60
|
+
# Decryption
|
|
61
|
+
pin = bytearray("1234", 'utf-8')
|
|
62
|
+
password = bytearray("password", 'utf-8')
|
|
63
|
+
iterations = pyaescbc.generate_pin_iterations(pin, delete_keys=True)
|
|
64
|
+
authdata = bytearray("user=toto", 'utf-8') # Optional authentication data (can be None)
|
|
65
|
+
decrypted_data = pyaescbc.decrypt(encrypted_bundle, password, iterations, authdata=authdata, delete_keys=True)
|
|
66
|
+
|
|
67
|
+
print(decrypted_data)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+

|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
## Authors
|
|
75
|
+
|
|
76
|
+
- Artezaru <artezaru.github@proton.me>
|
|
77
|
+
|
|
78
|
+
- **Git Plateform**: https://github.com/Artezaru/pyaescbc.git
|
|
79
|
+
- **Online Documentation**: https://Artezaru.github.io/pyaescbc
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
Install with pip
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
pip install pyaescbc
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
pip install git+https://github.com/Artezaru/pyaescbc.git
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Clone with git
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
git clone https://github.com/Artezaru/pyaescbc.git
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Copyright 2025 Artezaru
|
|
102
|
+
|
|
103
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
104
|
+
you may not use this file except in compliance with the License.
|
|
105
|
+
You may obtain a copy of the License at
|
|
106
|
+
|
|
107
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
108
|
+
|
|
109
|
+
Unless required by applicable law or agreed to in writing, software
|
|
110
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
111
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
112
|
+
See the License for the specific language governing permissions and
|
|
113
|
+
limitations under the License.
|
|
114
|
+
|
pyaescbc-0.1.0/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# pyaescbc
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
AES-CBC encryption tools based on crytography package !
|
|
6
|
+
|
|
7
|
+
The package `pyaescbc` provides functions to encrypt and decrypt data using the AES-CBC encryption mode. The package is written in Python and uses the `cryptography` library for the AES encryption and decryption. The package also provides functions to generate a derived key from a password and a pin, and to create an HMAC value from the derived key, IV, and ciphertext. The package is designed to be easy to use and secure, and it is suitable for encrypting sensitive data.
|
|
8
|
+
|
|
9
|
+
General usage of the package includes:
|
|
10
|
+
|
|
11
|
+
``` python
|
|
12
|
+
import pyaescbc
|
|
13
|
+
|
|
14
|
+
# Encryption
|
|
15
|
+
cleardata = bytearray("Hello, World!", 'utf-8')
|
|
16
|
+
pin = bytearray("1234", 'utf-8')
|
|
17
|
+
password = bytearray("password", 'utf-8')
|
|
18
|
+
iterations = pyaescbc.generate_pin_iterations(pin, delete_keys=True)
|
|
19
|
+
authdata = bytearray("user=toto", 'utf-8') # Optional authentication data (can be None)
|
|
20
|
+
encrypted_bundle = pyaescbc.encrypt(cleardata, password, iterations, authdata=authdata, delete_keys=True)
|
|
21
|
+
|
|
22
|
+
# Decryption
|
|
23
|
+
pin = bytearray("1234", 'utf-8')
|
|
24
|
+
password = bytearray("password", 'utf-8')
|
|
25
|
+
iterations = pyaescbc.generate_pin_iterations(pin, delete_keys=True)
|
|
26
|
+
authdata = bytearray("user=toto", 'utf-8') # Optional authentication data (can be None)
|
|
27
|
+
decrypted_data = pyaescbc.decrypt(encrypted_bundle, password, iterations, authdata=authdata, delete_keys=True)
|
|
28
|
+
|
|
29
|
+
print(decrypted_data)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
## Authors
|
|
37
|
+
|
|
38
|
+
- Artezaru <artezaru.github@proton.me>
|
|
39
|
+
|
|
40
|
+
- **Git Plateform**: https://github.com/Artezaru/pyaescbc.git
|
|
41
|
+
- **Online Documentation**: https://Artezaru.github.io/pyaescbc
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install with pip
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pip install pyaescbc
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
pip install git+https://github.com/Artezaru/pyaescbc.git
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Clone with git
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
git clone https://github.com/Artezaru/pyaescbc.git
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
Copyright 2025 Artezaru
|
|
64
|
+
|
|
65
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
66
|
+
you may not use this file except in compliance with the License.
|
|
67
|
+
You may obtain a copy of the License at
|
|
68
|
+
|
|
69
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
70
|
+
|
|
71
|
+
Unless required by applicable law or agreed to in writing, software
|
|
72
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
73
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
74
|
+
See the License for the specific language governing permissions and
|
|
75
|
+
limitations under the License.
|
|
76
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# This file is used to configure the documentation of the package
|
|
2
|
+
# It is used by the Sphinx documentation generator to generate the documentation
|
|
3
|
+
# The documentation is generated in the docs folder of the package
|
|
4
|
+
# The documentation is generated in HTML and LaTeX format
|
|
5
|
+
|
|
6
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
7
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
8
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
9
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
10
|
+
|
|
11
|
+
# 0. Import the necessary modules
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
sys.path.insert(0, os.path.abspath("../.."))
|
|
16
|
+
|
|
17
|
+
# 1. Set the project informations
|
|
18
|
+
|
|
19
|
+
def read_version():
|
|
20
|
+
version_file = os.path.join(os.path.dirname(__file__), '..', '..', 'pyaescbc', '__version__.py')
|
|
21
|
+
with open(version_file, "r") as file:
|
|
22
|
+
exec(file.read())
|
|
23
|
+
return locals()["__version__"]
|
|
24
|
+
|
|
25
|
+
project = "pyaescbc"
|
|
26
|
+
copyright = "2025-%Y, Artezaru"
|
|
27
|
+
author = "Artezaru"
|
|
28
|
+
release = read_version()
|
|
29
|
+
|
|
30
|
+
# 2. General configuration
|
|
31
|
+
|
|
32
|
+
import pydata_sphinx_theme
|
|
33
|
+
html_theme = "pydata_sphinx_theme"
|
|
34
|
+
|
|
35
|
+
extensions = [
|
|
36
|
+
"sphinx.ext.autodoc", # Automatically document the code
|
|
37
|
+
"sphinx.ext.viewcode", # Add links to the code
|
|
38
|
+
"sphinx.ext.napoleon", # Support for Google and Numpy docstring formats
|
|
39
|
+
"sphinx.ext.githubpages", # Publish the documentation on GitHub
|
|
40
|
+
"sphinx.ext.autosummary", # Generate summaries of the modules
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
napoleon_google_docstring = False
|
|
44
|
+
napoleon_numpy_docstring = True
|
|
45
|
+
|
|
46
|
+
# 3. Options for Latex output
|
|
47
|
+
|
|
48
|
+
latex_elements = {
|
|
49
|
+
"papersize": "a4paper",
|
|
50
|
+
"pointsize": "10pt",
|
|
51
|
+
"preamble": "",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
latex_documents = [
|
|
55
|
+
("index", "pyaescbc.tex", "pyaescbc Documentation",
|
|
56
|
+
"Artezaru", "manual"),
|
|
57
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Welcome to pyaescbc's documentation!
|
|
2
|
+
=========================================================================================
|
|
3
|
+
|
|
4
|
+
Description of the package
|
|
5
|
+
--------------------------
|
|
6
|
+
|
|
7
|
+
AES-CBC encryption tools based on crytography package !
|
|
8
|
+
|
|
9
|
+
The package `pyaescbc` provides functions to encrypt and decrypt data using the AES-CBC encryption mode.
|
|
10
|
+
The package is written in Python and uses the `cryptography` library for the AES encryption and decryption.
|
|
11
|
+
The package also provides functions to generate a derived key from a password and a pin, and to create an HMAC value from the derived key, IV, and ciphertext.
|
|
12
|
+
The package is designed to be easy to use and secure, and it is suitable for encrypting sensitive data.
|
|
13
|
+
|
|
14
|
+
The encryption process is designed as follow :
|
|
15
|
+
|
|
16
|
+
.. image:: ../../pyaescbc/resources/encrypt.png
|
|
17
|
+
:align: center
|
|
18
|
+
|
|
19
|
+
The decryption process is designed as follow :
|
|
20
|
+
|
|
21
|
+
.. image:: ../../pyaescbc/resources/decrypt.png
|
|
22
|
+
:align: center
|
|
23
|
+
|
|
24
|
+
Contents
|
|
25
|
+
--------
|
|
26
|
+
|
|
27
|
+
The documentation is divided into the following sections:
|
|
28
|
+
|
|
29
|
+
- **Installation**: This section describes how to install the package.
|
|
30
|
+
- **API Reference**: This section contains the documentation of the package's API.
|
|
31
|
+
- **Usage**: This section contains the documentation of how to use the package.
|
|
32
|
+
|
|
33
|
+
.. toctree::
|
|
34
|
+
:maxdepth: 1
|
|
35
|
+
:caption: Contents:
|
|
36
|
+
|
|
37
|
+
./installation
|
|
38
|
+
./api
|
|
39
|
+
./usage
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Author
|
|
43
|
+
------
|
|
44
|
+
|
|
45
|
+
The package ``pyaescbc`` was created by the following authors:
|
|
46
|
+
|
|
47
|
+
- Artezaru <artezaru.github@proton.me>
|
|
48
|
+
|
|
49
|
+
You can access the package and the documentation with the following URL:
|
|
50
|
+
|
|
51
|
+
- **Git Plateform**: https://github.com/Artezaru/pyaescbc.git
|
|
52
|
+
- **Online Documentation**: https://Artezaru.github.io/pyaescbc
|
|
53
|
+
|
|
54
|
+
License
|
|
55
|
+
-------
|
|
56
|
+
|
|
57
|
+
Please refer to the [LICENSE] file for the license of the package.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Installation
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
To install ``pyaescbc``, you can use the following command:
|
|
5
|
+
|
|
6
|
+
.. code-block:: bash
|
|
7
|
+
|
|
8
|
+
pip install pyaescbc
|
|
9
|
+
|
|
10
|
+
Or install it directly from the GitHub repository using:
|
|
11
|
+
|
|
12
|
+
.. code-block:: bash
|
|
13
|
+
|
|
14
|
+
pip install git+https://github.com/Artezaru/pyaescbc.git
|
|
15
|
+
|
|
16
|
+
Development Installation
|
|
17
|
+
------------------------------
|
|
18
|
+
|
|
19
|
+
To install the package for development, first clone the repository using:
|
|
20
|
+
|
|
21
|
+
.. code-block:: bash
|
|
22
|
+
|
|
23
|
+
git clone https://github.com/Artezaru/pyaescbc.git
|
|
24
|
+
|
|
25
|
+
Then, go to the directory and run the following command:
|
|
26
|
+
|
|
27
|
+
.. code-block:: bash
|
|
28
|
+
|
|
29
|
+
pip install -e .
|
|
30
|
+
|
|
31
|
+
Use ``-e .[dev]`` to install it with the development dependencies.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Usage
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
Package usage
|
|
5
|
+
-------------
|
|
6
|
+
|
|
7
|
+
To encrypt a message, use the following code, available in the `examples` directory of the package:
|
|
8
|
+
|
|
9
|
+
.. literalinclude:: ../../examples/encrypt.py
|
|
10
|
+
|
|
11
|
+
The iteration can also be generated randomly, using :func:`pyaescbc.generate_random_iterations`.
|
|
12
|
+
|
|
13
|
+
Type convertion
|
|
14
|
+
-----------------
|
|
15
|
+
|
|
16
|
+
If your clear data is a string, you can convert them to bytearray using the following code:
|
|
17
|
+
|
|
18
|
+
.. code-block:: python
|
|
19
|
+
|
|
20
|
+
# Convert a string to bytearray
|
|
21
|
+
string = "Hello, World!"
|
|
22
|
+
byte_array = bytearray(string, 'utf-8')
|
|
23
|
+
|
|
24
|
+
Similarly, after decrypting, you can convert the bytearray back to a string using the following code:
|
|
25
|
+
|
|
26
|
+
.. code-block:: python
|
|
27
|
+
|
|
28
|
+
# Convert a bytearray to string
|
|
29
|
+
decrypted_string = byte_array.decode('utf-8')
|
|
30
|
+
print(decrypted_string) # Output: Hello, World!
|
|
31
|
+
|
|
32
|
+
For encrypted data (ie the ``encrypted_bundle``), the type is a bytearray but it can't be converted to a string using ``utf-8``.
|
|
33
|
+
This is because the encrypted data is not a valid UTF-8 string.
|
|
34
|
+
|
|
35
|
+
I recommend to save the encrypted data in a file or a database as a bytearray, and then read it back as a bytearray when you need to decrypt it.
|
|
36
|
+
|
|
37
|
+
Otherwise, you can convert the bytearray to a base64 string using the following code:
|
|
38
|
+
|
|
39
|
+
.. code-block:: python
|
|
40
|
+
|
|
41
|
+
import base64
|
|
42
|
+
|
|
43
|
+
# Convert bytearray to base64 string
|
|
44
|
+
encrypted_bundle = bytearray(b'\x00\x01\x02\x03')
|
|
45
|
+
base64_string = base64.b64encode(encrypted_bundle).decode('utf-8')
|
|
46
|
+
print(base64_string)
|
|
47
|
+
|
|
48
|
+
The base64 string can be saved in a file or a database as a string, and then read it back as a base64 string when you need to decrypt it.
|
|
49
|
+
To reconvert the base64 string to a bytearray, you can use the following code:
|
|
50
|
+
|
|
51
|
+
.. code-block:: python
|
|
52
|
+
|
|
53
|
+
# Convert base64 string to bytearray
|
|
54
|
+
base64_string = "AAECAw=="
|
|
55
|
+
encrypted_bundle = bytearray(base64.b64decode(base64_string))
|
|
56
|
+
print(encrypted_bundle)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import pyaescbc
|
|
2
|
+
|
|
3
|
+
# Encryption
|
|
4
|
+
cleardata = bytearray("Hello, World!", 'utf-8')
|
|
5
|
+
pin = bytearray("1234", 'utf-8')
|
|
6
|
+
password = bytearray("password", 'utf-8')
|
|
7
|
+
iterations = pyaescbc.generate_pin_iterations(pin, delete_keys=True)
|
|
8
|
+
authdata = bytearray("user=toto", 'utf-8') # Optional authentication data (can be None)
|
|
9
|
+
encrypted_bundle = pyaescbc.encrypt(cleardata, password, iterations, authdata=authdata, delete_keys=True)
|
|
10
|
+
|
|
11
|
+
# Decryption
|
|
12
|
+
pin = bytearray("1234", 'utf-8')
|
|
13
|
+
password = bytearray("password", 'utf-8')
|
|
14
|
+
iterations = pyaescbc.generate_pin_iterations(pin, delete_keys=True)
|
|
15
|
+
authdata = bytearray("user=toto", 'utf-8') # Optional authentication data (can be None)
|
|
16
|
+
decrypted_data = pyaescbc.decrypt(encrypted_bundle, password, iterations, authdata=authdata, delete_keys=True)
|
|
17
|
+
|
|
18
|
+
print(decrypted_data)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Copyright 2025 Artezaru
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .__version__ import __version__
|
|
16
|
+
|
|
17
|
+
from .decrypt_AES_CBC import decrypt_AES_CBC
|
|
18
|
+
from .derive_key import derive_key
|
|
19
|
+
from .encrypt_AES_CBC import encrypt_AES_CBC
|
|
20
|
+
|
|
21
|
+
from .cleardata_to_encrypted_bundle import cleardata_to_encrypted_bundle
|
|
22
|
+
encrypt = cleardata_to_encrypted_bundle
|
|
23
|
+
from .encrypted_bundle_to_cleardata import encrypted_bundle_to_cleardata
|
|
24
|
+
decrypt = encrypted_bundle_to_cleardata
|
|
25
|
+
|
|
26
|
+
from .create_encrypted_bundle import create_encrypted_bundle
|
|
27
|
+
from .extract_cryptography_components import extract_cryptography_components
|
|
28
|
+
|
|
29
|
+
from .generate_random_iterations import generate_random_iterations
|
|
30
|
+
from .generate_pin_iterations import generate_pin_iterations
|
|
31
|
+
|
|
32
|
+
from .random_bytearray import random_bytearray
|
|
33
|
+
from .random_iv import random_iv
|
|
34
|
+
from .random_salt import random_salt
|
|
35
|
+
|
|
36
|
+
from .create_hmac import create_hmac
|
|
37
|
+
from .check_hmac import check_hmac
|
|
38
|
+
from .auth_error import AuthError
|
|
39
|
+
|
|
40
|
+
from .delete_bytearray import delete_bytearray
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"__version__",
|
|
44
|
+
"decrypt_AES_CBC",
|
|
45
|
+
"derive_key",
|
|
46
|
+
"encrypt_AES_CBC",
|
|
47
|
+
"cleardata_to_encrypted_bundle",
|
|
48
|
+
"encrypt",
|
|
49
|
+
"encrypted_bundle_to_cleardata",
|
|
50
|
+
"decrypt",
|
|
51
|
+
"create_encrypted_bundle",
|
|
52
|
+
"extract_cryptography_components",
|
|
53
|
+
"generate_random_iterations",
|
|
54
|
+
"generate_pin_iterations",
|
|
55
|
+
"random_bytearray",
|
|
56
|
+
"random_iv",
|
|
57
|
+
"random_salt",
|
|
58
|
+
"create_hmac",
|
|
59
|
+
"check_hmac",
|
|
60
|
+
"AuthError",
|
|
61
|
+
"delete_bytearray",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
|