-
Notifications
You must be signed in to change notification settings - Fork 2
/
DecryptForm.cs
106 lines (96 loc) · 2.81 KB
/
DecryptForm.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
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FileEncrypter
{
public partial class DecryptForm : Form
{
AesCrypter aes;
public DecryptForm(AesCrypter aesArg)
{
InitializeComponent();
aes = aesArg;
}
public static byte[] ReadFully(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
private void Button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
// countinue in OpenFileDialog1_FileOk func
}
private void OpenFileDialog1_FileOk(object sender, CancelEventArgs e)
{
saveFileDialog1.ShowDialog();
// countinue in next
}
public void setProgress(int progress)
{
if (InvokeRequired)
{
this.Invoke(new Action<int>(setProgress), new object[] { progress });
return;
}
progressBar1.Value = progress;
}
public void setColor(Color color)
{
if (InvokeRequired)
{
this.Invoke(new Action<Color>(setColor), new object[] { color });
return;
}
progressBar1.BackColor = color;
}
async void doSomthingAsych()
{
try
{
FileStream data = (FileStream)openFileDialog1.OpenFile();
setProgress(2);
Stream encrypted = aes.Decrypt(data);
setProgress(4);
FileStream s = (FileStream)saveFileDialog1.OpenFile();
setProgress(6);
encrypted.CopyTo(s);
encrypted.Close();
data.Close();
s.Close();
setProgress(10);
}
catch (Exception ex)
{
setColor(Color.Red);
appedConsole($"Error: {ex.ToString()}\n");
}
}
public void appedConsole(string s)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(appedConsole), new object[] { s });
return;
}
debugConsole.AppendText(s);
}
private void SaveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
progressBar1.BackColor = Color.Green;
progressBar1.Minimum = 0;
progressBar1.Maximum = 10;
Task.Run(new Action(doSomthingAsych));
}
}
}