-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (63 loc) · 2.43 KB
/
Copy pathProgram.cs
File metadata and controls
67 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using CryptoSoft.Models;
using CryptoSoft.Services;
class Program
{
static void Main(string[] args)
{
var appName = Assembly.GetEntryAssembly().GetName().Name;
if (args.Length < 4)
{
Console.WriteLine("Usage: CryptoSoft <command> <inputFile> <outputPath> <key>");
Console.WriteLine("Commands: encrypt, decrypt");
Console.WriteLine(appName);
return;
}
string command = args[0];
string inputFile = args[1];
string outputPath = args[2];
string key = args[3];
// Initialize the CryptoSoftConfig with the provided key
CryptoSoftConfig config = new CryptoSoftConfig(key);
try
{
if (command.Equals("encrypt", StringComparison.OrdinalIgnoreCase))
{
// Encrypt the file
EncryptData encryptData = new EncryptData(config);
string encryptedFilePath = encryptData.EncryptFile(inputFile);
string finalEncryptedFilePath = Path.Combine(outputPath, Path.GetFileName(encryptedFilePath));
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
File.Move(encryptedFilePath, finalEncryptedFilePath);
Console.WriteLine($"File encrypted to: {finalEncryptedFilePath}");
}
else if (command.Equals("decrypt", StringComparison.OrdinalIgnoreCase))
{
// Decrypt the file
DecryptData decryptData = new DecryptData(config);
string decryptedFilePath = decryptData.DecryptFile(inputFile);
string finalDecryptedFilePath = Path.Combine(outputPath, Path.GetFileName(decryptedFilePath));
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
File.Move(decryptedFilePath, finalDecryptedFilePath);
Console.WriteLine($"File decrypted to: {finalDecryptedFilePath}");
}
else
{
Console.WriteLine("Invalid command. Use 'encrypt' or 'decrypt'.");
}
}
catch (IOException ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}