Skip to content

Commit 57eb175

Browse files
committed
added sanitisation and refactored
1 parent c753bbd commit 57eb175

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Encryption App.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.28010.2016
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encryption App", "src\Encryption App.csproj", "{701B9935-7BF8-4BA2-861A-7764761C1318}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionApp", "src\EncryptionApp.csproj", "{701B9935-7BF8-4BA2-861A-7764761C1318}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/Backend/Encryptor.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public void AES_Encrypt(string iF, string oF, byte[] passwordBytes)
1616

1717
AES.KeySize = 256;
1818
AES.BlockSize = 128;
19+
AES.Padding = PaddingMode.PKCS7;
20+
AES.Mode = CipherMode.CBC;
21+
1922
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 100000);
2023
AES.Key = key.GetBytes(AES.KeySize / 8);
2124
AES.IV = key.GetBytes(AES.BlockSize / 8);
22-
AES.Padding = PaddingMode.PKCS7;
23-
AES.Mode = CipherMode.CBC;
2425

2526
using (var outFile = File.Create(oF))
2627
using (var cs = new CryptoStream(outFile, AES.CreateEncryptor(), CryptoStreamMode.Write))
@@ -60,17 +61,24 @@ public void AES_Decrypt(string iF, string oF, byte[] passwordBytes)
6061
AES.Key = key.GetBytes(AES.KeySize / 8);
6162
AES.IV = key.GetBytes(AES.BlockSize / 8);
6263

63-
using (var inFile = File.OpenRead(iF))
64-
using (var cs = new CryptoStream(inFile, AES.CreateDecryptor(), CryptoStreamMode.Read))
65-
using (var outFile = File.Create(oF))
64+
65+
try
6666
{
67+
using (var inFile = File.OpenRead(iF))
68+
using (var cs = new CryptoStream(inFile, AES.CreateDecryptor(), CryptoStreamMode.Read))
69+
using (var outFile = File.Create(oF))
70+
{
6771

68-
sbyte data;
69-
while ((data = (sbyte)cs.ReadByte()) != -1)
70-
outFile.WriteByte((byte)data);
72+
sbyte data;
73+
while ((data = (sbyte)cs.ReadByte()) != -1)
74+
outFile.WriteByte((byte)data);
7175

76+
}
7277
}
78+
catch (CryptographicException)
79+
{
7380

81+
}
7482
}
7583

7684
}

0 commit comments

Comments
 (0)