-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
150 lines (130 loc) · 5.21 KB
/
MainWindow.xaml.cs
File metadata and controls
150 lines (130 loc) · 5.21 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.IO;
using System.Windows;
using System.Security.Cryptography;
using MessageBox = System.Windows.Forms.MessageBox;
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
using System.Windows.Forms;
namespace Encryptie_Tools
{
public partial class MainWindow : Window
{
#region Variables
private string KeyName;
private string filePath_Keys;
public string FilePath_Keys
{
get { return filePath_Keys; }
set { filePath_Keys = value; }
}
#endregion
public MainWindow()
{
InitializeComponent();
FilePath_Keys = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\EncryptionTool_Data\\Keys";
string encryptedImagesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\EncryptionTool_Data\\Encrypted Images";
string decryptedImagesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\EncryptionTool_Data\\Decrypted Images";
string plainImagesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\EncryptionTool_Data\\Plain Images";
if (!Directory.Exists(FilePath_Keys))
{
Directory.CreateDirectory(FilePath_Keys);
}
if (!Directory.Exists(encryptedImagesPath))
{
Directory.CreateDirectory(encryptedImagesPath);
}
if (!Directory.Exists(decryptedImagesPath))
{
Directory.CreateDirectory(decryptedImagesPath);
}
if (!Directory.Exists(plainImagesPath))
{
Directory.CreateDirectory(plainImagesPath);
}
// Warn User about Stock File Locations
MessageBox.Show("The stock location for all files is in the Documents folder under EncryptionTool_Data\n\nThis can be changed from each windows top menu bar");
}
#region Kies Standaard Locatie
private void MenuKeyStorage_Click(object sender, RoutedEventArgs e)
{
using (FolderBrowserDialog dialog = new FolderBrowserDialog())
{
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
FilePath_Keys = dialog.SelectedPath;
}
}
}
#endregion
#region Generate Buttons and Coresponding Methods
private void BtnGenereerAES_Click(object sender, RoutedEventArgs e)
{
if (TxtSleutel.Text == "" || TxtSleutel.Text == null)
{
MessageBox.Show("No key name entered");
}
else
{
KeyName = TxtSleutel.Text;
// Generate a random AES key and IV
Aes aes = Aes.Create();
aes.KeySize = 128;
aes.BlockSize = 128;
aes.GenerateKey();
aes.GenerateIV();
// Convert the key and IV to Base64 strings
string keyBase64 = Convert.ToBase64String(aes.Key);
string ivBase64 = Convert.ToBase64String(aes.IV);
using (StreamWriter sw = new StreamWriter(FilePath_Keys + "/AES_" + KeyName + ".txt"))
{
sw.WriteLine(keyBase64);
sw.WriteLine(ivBase64);
}
MessageBox.Show("Key saved successfully");
}
}
private void BtnGenereerRSA_Click(object sender, RoutedEventArgs e)
{
if (FilePath_Keys == "" || FilePath_Keys == null)
{
MessageBox.Show("No key name entered");
}
else
{
KeyName = TxtSleutel.Text;
// Create an instance of RSACryptoServiceProvider
using (RSA rsa = RSA.Create())
{
rsa.KeySize = 2048;
// Export the public key as a string
string publicKey = rsa.ToXmlString(false);
// Export the private key as a string
string privateKey = rsa.ToXmlString(true);
// Write the public and private key to a sw
using (StreamWriter sw = new StreamWriter(FilePath_Keys + "\\RSA_Public_" + KeyName + ".xml"))
{
sw.Write(publicKey);
}
using (StreamWriter sw = new StreamWriter(FilePath_Keys + "\\RSA_Private_" + KeyName + ".xml"))
{
sw.Write(privateKey);
}
}
MessageBox.Show("Key saved successfully");
}
}
#endregion
#region AES & RSA Windows
private void MenuItemAES_Click(object sender, RoutedEventArgs e)
{
AESWindow aesWindow = new AESWindow(this);
aesWindow.ShowDialog();
}
private void MenuItemRSA_Click(object sender, RoutedEventArgs e)
{
RSAWindow rsaWindow = new RSAWindow(this);
rsaWindow.ShowDialog();
}
#endregion
}
}