Skip to content

Commit 78beba2

Browse files
Merge pull request #13 from sebastienrousseauhsbc/main
Update project configuration and dependencies
2 parents 6886856 + 647a915 commit 78beba2

File tree

9 files changed

+495
-98
lines changed

9 files changed

+495
-98
lines changed

.bandit.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exclude_dirs:
2+
- .git
3+
- .tox
4+
- "tests/*"
5+
- build
6+
- dist
7+
8+
skips:
9+
- B101

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
12
<p align="center">
23
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
34
</p>
@@ -9,7 +10,7 @@
910
</p>
1011

1112
<p align="center">
12-
<strong>A Python CLI application for generating RSA public and private key pairs using PyCryptodome</strong>
13+
<strong>A Python CLI application for generating RSA public and private key pairs using the cryptography library</strong>
1314
</p>
1415

1516
<p align="center">
@@ -20,10 +21,11 @@
2021
<a href="#development">Development</a> •
2122
<a href="#license">License</a>
2223
</p>
24+
<!-- markdownlint-enable MD033 MD041 -->
2325

2426
## Features
2527

26-
Encryption Helper is a robust Python package designed to simplify the process of creating RSA key pairs. It leverages the PyCryptodome library to offer:
28+
Encryption Helper is a robust Python package designed to simplify the process of creating RSA key pairs. It leverages the [cryptography][0] library to offer:
2729

2830
- Generation of 2048-bit RSA key pairs
2931
- Automatic saving of keys in PEM format
@@ -32,7 +34,7 @@ Encryption Helper is a robust Python package designed to simplify the process of
3234

3335
## Installation
3436

35-
This package requires Python 3.8 or later and uses PyCryptodome for cryptographic operations.
37+
This package requires Python 3.8 or later and uses cryptography for cryptographic operations.
3638

3739
### Using Poetry (recommended)
3840

@@ -43,7 +45,7 @@ Ensure you have Poetry installed, then follow these steps:
4345
git clone https://github.com/hsbc/encryption-helper-python.git
4446
cd encryption-helper-python
4547

46-
# Install dependencies (including PyCryptodome)
48+
# Install dependencies (including cryptography)
4749
poetry install
4850
```
4951

@@ -60,7 +62,7 @@ cd encryption-helper-python
6062
python -m venv venv
6163
source venv/bin/activate # On Windows use `venv\Scripts\activate`
6264

63-
# Install the package and its dependencies (including PyCryptodome)
65+
# Install the package and its dependencies (including cryptography)
6466
pip install .
6567
```
6668

@@ -91,21 +93,21 @@ python -m encryption_helper
9193

9294
These commands will:
9395

94-
- Use PyCryptodome to generate a 2048-bit RSA key pair
96+
- Use cryptography to generate a 2048-bit RSA key pair
9597
- Save the private key to `keys/pem/private-key.pem`
9698
- Save the public key to `keys/pem/public-key.pem`
9799
- Display both keys in the console
98100
- Log the key generation process
99101

100102
## Configuration
101103

102-
The key generation process uses PyCryptodome with the following specifications:
104+
The key generation process uses cryptography with the following specifications:
103105

104106
- Standard: PKCS#1
105107
- Type: RSA
106108
- Size: 2048 bits
107109

108-
To modify these settings, you'll need to edit the `generate_rsa_key()` function in `encryption_helper/main.py`. Refer to the PyCryptodome documentation for more advanced configurations.
110+
To modify these settings, you'll need to edit the `generate_rsa_key()` function in `encryption_helper/main.py`. Refer to the cryptography documentation for more advanced configurations.
109111

110112
## Development
111113

@@ -149,3 +151,6 @@ pydoc -w encryption_helper
149151
## License
150152

151153
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
154+
155+
156+
[0]: https://github.com/pyca/cryptography

encryption_helper/main.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
from pathlib import Path
99
from typing import Tuple
10-
from Crypto.PublicKey import RSA
10+
from cryptography.hazmat.primitives.asymmetric import rsa
11+
from cryptography.hazmat.primitives import serialization
12+
from cryptography.hazmat.backends import default_backend
1113
from .context import Context
1214

1315

@@ -41,18 +43,22 @@ def generate_rsa_key() -> Tuple[bytes, bytes]:
4143

4244
try:
4345
# Generate the RSA key pair
44-
key_pair = RSA.generate(2048)
46+
key_pair = rsa.generate_private_key(
47+
public_exponent=65537, key_size=2048, backend=default_backend()
48+
)
4549

4650
# Export the private key
47-
private_key = key_pair.export_key(
48-
format="PEM",
49-
# passphrase="1password", # Uncomment if you want to use a passphrase
50-
# pkcs=1,
51-
# protection="scryptAndAES256-CBC",
51+
private_key = key_pair.private_bytes(
52+
encoding=serialization.Encoding.PEM,
53+
format=serialization.PrivateFormat.PKCS8,
54+
encryption_algorithm=serialization.NoEncryption(), # Use a passphrase if needed
5255
)
5356

5457
# Export the public key
55-
public_key = key_pair.publickey().export_key(format="PEM")
58+
public_key = key_pair.public_key().public_bytes(
59+
encoding=serialization.Encoding.PEM,
60+
format=serialization.PublicFormat.SubjectPublicKeyInfo,
61+
)
5662

5763
# Create the directory for storing keys
5864
keys_dir = Path("keys/pem")

encryption_helper/utils/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!-- markdownlint-disable MD033 MD041 -->
2+
<p align="center">
3+
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
4+
</p>
5+
6+
<h1 align="center">Encryption Helper Python</h1>
7+
8+
<p align="center">
9+
<img src="../../assets/banner.jpg" alt="Encryption Helper Banner">
10+
</p>
11+
12+
<h2 align="center">Checks and I/O Modules Overview</h2>
13+
14+
<p align="center">
15+
<strong>This package includes various modules for encryption helper functionalities.</strong>
16+
</p>
17+
18+
<p align="center">
19+
<a href="#checks-module">Checks Module</a> •
20+
<a href="#io-modules">I/O Modules</a> •
21+
<a href="#license">License</a>
22+
</p>
23+
<!-- markdownlint-enable MD033 MD041 -->
24+
25+
## Checks Module
26+
27+
The Checks module in the `encryption_helper` package provides utility functions for input validation.
28+
29+
For detailed documentation, please refer to the `README.md` file in the respective folder:
30+
31+
- [Checks Module](checks/README.md)
32+
33+
## I/O Modules
34+
35+
The I/O modules in the `encryption_helper` package provide functionalities for reading and writing files in binary mode.
36+
37+
- **Read File Module**: Functions to read text files in binary mode.
38+
- **Write File Module**: Functions to write text files in binary mode.
39+
40+
For detailed documentation, please refer to the `README.md` files in the respective folders:
41+
42+
- [Read File Module](io/README.md)
43+
- [Write File Module](io/README.md)
44+
45+
## License
46+
47+
This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details.

0 commit comments

Comments
 (0)