-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
100 lines (84 loc) · 2.68 KB
/
Program.cs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using AESConsoleApp;
while (true)
{
DisplayMenu();
var operation = Console.ReadLine();
switch (operation)
{
case "1":
HandleEncryption();
break;
case "2":
HandleDecryption();
break;
default:
return;
}
}
#region Helper
static void DisplayMenu()
{
Console.Clear();
Console.WriteLine("Select Operation:");
Console.WriteLine("1. AES Encrypt");
Console.WriteLine("2. AES Decrypt");
Console.WriteLine("Any other key to Quit.");
}
static void HandleEncryption()
{
Console.Clear();
Console.WriteLine("AES Encryption");
Console.WriteLine("Note: Key and Initialization Vector (IV) must be Base64 strings.");
var key = PromptUserInput("Enter AES Key:");
var iv = PromptUserInput("Enter AES Initialization Vector (IV):");
var plainText = PromptUserInput("Enter Plain Text:");
try
{
var encryptedText = AES.Encrypt(plainText, key, iv);
DisplayResult("Encrypted Text:", encryptedText);
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
}
static void HandleDecryption()
{
Console.Clear();
Console.WriteLine("AES Decryption");
Console.WriteLine("Note: Key and Initialization Vector (IV) must be Base64 strings.");
var key = PromptUserInput("Enter AES Key:");
var iv = PromptUserInput("Enter AES Initialization Vector (IV):");
var encryptedText = PromptUserInput("Enter Encrypted Text:");
try
{
var decryptedText = AES.Decrypt(encryptedText, key, iv);
DisplayResult("Decrypted Text:", decryptedText);
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
}
static string PromptUserInput(string message)
{
Console.WriteLine(message);
return Console.ReadLine();
}
static void DisplayResult(string label, string result)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"{label} {result}");
Console.ResetColor();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
static void DisplayError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Error: {message}");
Console.ResetColor();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
#endregion