FileEncryptor1 1.0.0
dotnet add package FileEncryptor1 --version 1.0.0
NuGet\Install-Package FileEncryptor1 -Version 1.0.0
<PackageReference Include="FileEncryptor1" Version="1.0.0" />
paket add FileEncryptor1 --version 1.0.0
#r "nuget: FileEncryptor1, 1.0.0"
// Install FileEncryptor1 as a Cake Addin #addin nuget:?package=FileEncryptor1&version=1.0.0 // Install FileEncryptor1 as a Cake Tool #tool nuget:?package=FileEncryptor1&version=1.0.0
FileEncryptor Package Usage
Overview
The FileEncryptor
package provides functionality to encrypt and decrypt files using AES encryption. This guide demonstrates how to use the package in a simple console application.
Setup
Create a Console Application: Start by creating a new console application in your development environment.
Add the FileEncryptor Package: Make sure you have the
FileEncryptor
package referenced in your project.
Sample Code
Use the following code snippet in your Main
method to demonstrate how to encrypt and decrypt a file.
using System;
using System.IO;
namespace FileEncryptorDemo
{
class Program
{
static void Main(string[] args)
{
string inputFilePath = @"C:\Path\To\Your\File.zip"; // Change to your file path
string outputDirectory = @"C:\Path\To\Output"; // Change to your output directory
// Ensure the output directory exists
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
// Create an instance of the IFileEncryptor
IFileEncryptor fileEncryptor = new FileEncryptor();
// Encrypt the file
string encryptedFilePath = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(inputFilePath) + ".nbk");
fileEncryptor.EncryptFile(inputFilePath, outputDirectory);
Console.WriteLine($"File encrypted to: {encryptedFilePath}");
// Decrypt the file
string decryptedFilePath = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(inputFilePath));
fileEncryptor.DecryptFile(encryptedFilePath, outputDirectory);
Console.WriteLine($"File decrypted to: {decryptedFilePath}");
}
}
}
## Explanation
- **File Paths**: Update the `inputFilePath` and `outputDirectory` variables to point to the actual file you want to encrypt and the directory where you want the output files to be saved.
- **Creating the Output Directory**: The code checks if the specified output directory exists and creates it if it doesn't.
- **Encrypting the File**: The `EncryptFile` method is called to encrypt the input file, and the encrypted file will be saved with a `.nbk` extension.
- **Decrypting the File**: The `DecryptFile` method is called to decrypt the previously encrypted file, restoring the original file extension.
## Notes
- Ensure the file paths are correct, and the input file exists.
- You may want to add error handling to manage exceptions, such as file not found or permission issues.
- This example assumes that the `FileEncryptor` class implements the `EncryptFile` and `DecryptFile` methods as previously discussed.
## Conclusion
This simple console application serves as a demonstration of how to use the `FileEncryptor` package for file encryption and decryption, showcasing the key functionalities you've implemented.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 79 | 10/21/2024 |