Skip to content

Commit d8b713d

Browse files
committed
fixed all
1 parent 83cbdd8 commit d8b713d

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/Backend/AESCryptoManager.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,27 @@ public void EncryptBytes(string inputFile, string outFile, byte[] passwordBytes)
2424
// Derives a key using PBKDF2 from the password and a salts
2525
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 100000);
2626

27-
2827
// Set actual IV and key
2928
aes.Key = key.GetBytes(aes.KeySize / 8);
3029
aes.IV = key.GetBytes(aes.BlockSize / 8);
3130

32-
long len = new FileInfo(inputFile).Length;
33-
3431
using (var outFileStream = File.Create(outFile))
3532
using (var cs = new CryptoStream(outFileStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
36-
using (var inFile = File.OpenRead(inputFile))
33+
using (var inFile = new BinaryReader(File.OpenRead(inputFile)))
3734
{
38-
39-
using (var br = new BinaryReader(inFile))
35+
while (true)
4036
{
41-
42-
sbyte data;
43-
while ((data = (sbyte)inFile.ReadByte()) != -1)
44-
cs.WriteByte((byte)data);
45-
37+
try
38+
{
39+
var data = (byte)inFile.ReadByte();
40+
cs.WriteByte(data);
41+
}
42+
catch (EndOfStreamException)
43+
{
44+
break;
45+
}
4646
}
47+
4748
}
4849

4950
}
@@ -74,23 +75,24 @@ public bool DecryptBytes(string inputFile, string outFile, byte[] passwordBytes)
7475
aes.Key = key.GetBytes(aes.KeySize / 8);
7576
aes.IV = key.GetBytes(aes.BlockSize / 8);
7677

77-
long len = new FileInfo(inputFile).Length;
78-
7978
using (var outFileStream = File.Create(outFile))
80-
using (var cs = new CryptoStream(outFileStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
81-
using (var inFile = File.OpenRead(inputFile))
79+
using (var cs = new CryptoStream(outFileStream, aes.CreateDecryptor(), CryptoStreamMode.Write))
80+
using (var inFile = new BinaryReader(File.OpenRead(inputFile)))
8281
{
83-
84-
using (var br = new BinaryReader(inFile))
82+
while (true)
8583
{
86-
87-
sbyte data;
88-
while ((data = (sbyte)inFile.ReadByte()) != -1)
89-
cs.WriteByte((byte)data);
90-
84+
try
85+
{
86+
var data = (byte)inFile.ReadByte();
87+
cs.WriteByte(data);
88+
}
89+
catch (EndOfStreamException)
90+
{
91+
break;
92+
}
9193
}
92-
}
9394

95+
}
9496
}
9597
}
9698

src/UI/MainWindow.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public MainWindow()
2020
InitializeComponent();
2121
DropDown.ItemsSource = _dropDownItems;
2222
DropDown.SelectedIndex = 0;
23-
2423
}
2524

2625
private void MenuItem_Click(object sender, RoutedEventArgs e)
@@ -84,7 +83,6 @@ private void Decrypt_Click(object sender, RoutedEventArgs e)
8483
if (worked)
8584
{
8685
File.Copy(Path.GetTempPath() + "tempdata.ini", outFilePath, true);
87-
Console.WriteLine("yay");
8886
}
8987

9088
MessageBox.Show(!worked ? "Wrong Password" : "Successfully Decrypted");

0 commit comments

Comments
 (0)