Introduction

This document describes a File Encryption and Decryption Utility implemented in Python. This utility enables users to securely encrypt and decrypt files using a password-derived key. The utility leverages the cryptography library, which provides a robust framework for implementing AES (Advanced Encryption Standard) encryption.

See Password_Srength_Checker


Purpose

The utility allows users to:

This utility is useful for securing sensitive data in environments where file access may not be fully controlled.


Requirements

To run this script, you need:

Python 3.x cryptography library: You can install it using:

pip install cryptography


Script Structure

The Python script is structured as follows:

  1. Key Generation: generate_key function derives a 256-bit encryption key from a password using PBKDF2 (Password-Based Key Derivation Function 2) with SHA-256 hashing.
  2. File Encryption: encrypt_file function encrypts the contents of a file using the generated key.
  3. File Decryption: decrypt_file function decrypts an encrypted file using the same key.
  4. Main Function: main function prompts the user for inputs and orchestrates the encryption/decryption process.

Code Explanation

Key Generation Function

Function: generate_key

The generate_key function generates a 256-bit encryption key from a user-provided password using PBKDF2, a password-based key derivation function. This function ensures that the password is securely transformed into a key suitable for AES encryption.