Skip to content

Commit

Permalink
Merge pull request #4 from sd416/dev
Browse files Browse the repository at this point in the history
Added support for media files
  • Loading branch information
sd416 authored Dec 17, 2024
2 parents 0996c09 + a97b6f5 commit 2b8235f
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 180 deletions.
88 changes: 72 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,108 @@
# File Encryptor

File Encryptor is a command-line tool written in Go that provides secure file encryption and decryption using either RSA key pairs or password-based encryption.
File Encryptor is a command-line tool written in Go that provides secure file encryption and decryption using either RSA key pairs or password-based encryption. It now supports **all file types**, including text files, media files (e.g., images, videos), and office documents (e.g., XLS, DOCX, PDF).

## Features

- Encrypt files using RSA public keys or passwords
- Decrypt files using RSA private keys or passwords
- Hybrid encryption: RSA for key exchange, AES for file content
- Support for both PEM and OpenSSH format keys
- Automatically preserve and restore the original file extensions
- Detailed logging for transparency and debugging
- Support for **all file types**: text, images (JPG, PNG), videos, spreadsheets, and more
- Parallel processing for faster encryption and decryption of large files

## Installation

1. Ensure you have Go installed on your system (version 1.16 or later).
- Verify with:
```bash
go version
```

2. Clone this repository:
```
```bash
git clone https://github.com/yourusername/file-encryptor.git
```

3. Navigate to the project directory:
```
```bash
cd file-encryptor
```

4. Build the project:
```
go build -o file-encryptor
```bash
go build -o file-encryptor main.go
```

## Usage

### Generate an RSA Key Pair
To generate an RSA key pair (private and public key) in your current folder:
```bash
ssh-keygen -t rsa -b 4096 -f my_ssh_key
```
- This creates `my_ssh_key` (private key) and `my_ssh_key.pub` (public key).

---

### Encryption

To encrypt a file using an RSA public key:
#### Encrypt a file using an RSA public key:
```bash
./file-encryptor -e --file <input_file> --key my_ssh_key.pub
```
./file-encryptor -e --file <input_file> --key <public_key_file>
Example:
```bash
./file-encryptor -e --file picture.jpg --key my_ssh_key.pub
```
- The encrypted file will be saved as `picture.jpg.enc`.

To encrypt a file using a password:
```
#### Encrypt a file using a password:
```bash
./file-encryptor -e --file <input_file> --password <your_password>
```
Example:
```bash
./file-encryptor -e --file document.pdf --password myStrongPassword123
```

---

### Decryption

To decrypt a file using an RSA private key:
#### Decrypt a file using an RSA private key:
```bash
./file-encryptor -d --file <encrypted_file> --key my_ssh_key
```
./file-encryptor -d --file <encrypted_file> --key <private_key_file>
Example:
```bash
./file-encryptor -d --file picture.jpg.enc --key my_ssh_key
```
- The decrypted file will retain its original extension (e.g., `picture.jpg`).

To decrypt a file using a password:
```
#### Decrypt a file using a password:
```bash
./file-encryptor -d --file <encrypted_file> --password <your_password>
```
Example:
```bash
./file-encryptor -d --file document.pdf.enc --password myStrongPassword123
```

---

## Security Notes

- Always use strong, unique passwords for password-based encryption.
- Keep your private keys secure and never share them.
- This tool uses AES-256 for file encryption and RSA for key exchange.
- Password-based encryption uses PBKDF2 for key derivation and HMAC for integrity verification.
- This tool uses:
- **AES-256** for file encryption (symmetric encryption).
- **RSA** for secure key exchange (asymmetric encryption).
- **PBKDF2** for key derivation in password-based encryption.
- HMAC for integrity verification.
- File extensions are preserved automatically during encryption and restored after decryption.

## Contributing

Expand All @@ -69,4 +114,15 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Disclaimer

This tool is provided as-is, without any warranties. Always ensure you have backups of your important files before encryption.
This tool is provided as-is, without any warranties. Always ensure you have backups of your important files before encryption.

---

**File Support Note**:
- The tool supports all file types, including:
- **Text**: TXT, CSV, JSON
- **Media**: JPG, PNG, MP4
- **Documents**: DOCX, PDF, XLS
- **Others**: Any other binary file format.

Example usage ensures seamless encryption and decryption without data corruption.
5 changes: 2 additions & 3 deletions cmd/file-encryptor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

"file-encryptor/pkg/crypto"
Expand Down Expand Up @@ -104,7 +103,7 @@ func handleDecryption(file, key, password string, logger *logging.Logger) (strin
return "", fmt.Errorf("error initializing decryptor: %v", err)
}

outputFile := strings.TrimSuffix(file, filepath.Ext(file))
outputFile := strings.TrimSuffix(file, ".enc")
err = fileops.DecryptFile(file, outputFile, decryptor, logger)
return outputFile, err
}
}
Loading

0 comments on commit 2b8235f

Please sign in to comment.