Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exclude_dirs:
- .git
- .tox
- "tests/*"
- build
- dist

skips:
- B101
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- markdownlint-disable MD033 MD041 -->
<p align="center">
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
</p>
Expand All @@ -9,7 +10,7 @@
</p>

<p align="center">
<strong>A Python CLI application for generating RSA public and private key pairs using PyCryptodome</strong>
<strong>A Python CLI application for generating RSA public and private key pairs using the cryptography library</strong>
</p>

<p align="center">
Expand All @@ -20,10 +21,11 @@
<a href="#development">Development</a> •
<a href="#license">License</a>
</p>
<!-- markdownlint-enable MD033 MD041 -->

## Features

Encryption Helper is a robust Python package designed to simplify the process of creating RSA key pairs. It leverages the PyCryptodome library to offer:
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:

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

## Installation

This package requires Python 3.8 or later and uses PyCryptodome for cryptographic operations.
This package requires Python 3.8 or later and uses cryptography for cryptographic operations.

### Using Poetry (recommended)

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

# Install dependencies (including PyCryptodome)
# Install dependencies (including cryptography)
poetry install
```

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

# Install the package and its dependencies (including PyCryptodome)
# Install the package and its dependencies (including cryptography)
pip install .
```

Expand Down Expand Up @@ -91,21 +93,21 @@ python -m encryption_helper

These commands will:

- Use PyCryptodome to generate a 2048-bit RSA key pair
- Use cryptography to generate a 2048-bit RSA key pair
- Save the private key to `keys/pem/private-key.pem`
- Save the public key to `keys/pem/public-key.pem`
- Display both keys in the console
- Log the key generation process

## Configuration

The key generation process uses PyCryptodome with the following specifications:
The key generation process uses cryptography with the following specifications:

- Standard: PKCS#1
- Type: RSA
- Size: 2048 bits

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.
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.

## Development

Expand Down Expand Up @@ -149,3 +151,6 @@ pydoc -w encryption_helper
## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.


[0]: https://github.com/pyca/cryptography
22 changes: 14 additions & 8 deletions encryption_helper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

from pathlib import Path
from typing import Tuple
from Crypto.PublicKey import RSA
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
from .context import Context


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

try:
# Generate the RSA key pair
key_pair = RSA.generate(2048)
key_pair = rsa.generate_private_key(
public_exponent=65537, key_size=2048, backend=default_backend()
)

# Export the private key
private_key = key_pair.export_key(
format="PEM",
# passphrase="1password", # Uncomment if you want to use a passphrase
# pkcs=1,
# protection="scryptAndAES256-CBC",
private_key = key_pair.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(), # Use a passphrase if needed
)

# Export the public key
public_key = key_pair.publickey().export_key(format="PEM")
public_key = key_pair.public_key().public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
)

# Create the directory for storing keys
keys_dir = Path("keys/pem")
Expand Down
47 changes: 47 additions & 0 deletions encryption_helper/utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- markdownlint-disable MD033 MD041 -->
<p align="center">
<img src="https://www.hsbc.com/-/files/hsbc/header/hsbc-logo-200x25.svg" alt="HSBC Logo" width="200" title="HSBC Logo">
</p>

<h1 align="center">Encryption Helper Python</h1>

<p align="center">
<img src="../../assets/banner.jpg" alt="Encryption Helper Banner">
</p>

<h2 align="center">Checks and I/O Modules Overview</h2>

<p align="center">
<strong>This package includes various modules for encryption helper functionalities.</strong>
</p>

<p align="center">
<a href="#checks-module">Checks Module</a> •
<a href="#io-modules">I/O Modules</a> •
<a href="#license">License</a>
</p>
<!-- markdownlint-enable MD033 MD041 -->

## Checks Module

The Checks module in the `encryption_helper` package provides utility functions for input validation.

For detailed documentation, please refer to the `README.md` file in the respective folder:

- [Checks Module](checks/README.md)

## I/O Modules

The I/O modules in the `encryption_helper` package provide functionalities for reading and writing files in binary mode.

- **Read File Module**: Functions to read text files in binary mode.
- **Write File Module**: Functions to write text files in binary mode.

For detailed documentation, please refer to the `README.md` files in the respective folders:

- [Read File Module](io/README.md)
- [Write File Module](io/README.md)

## License

This project is licensed under the MIT License. See the [LICENSE](../../LICENSE) file for details.
Loading