Skip to content

Commit 24a2eb7

Browse files
Commit
2 parents 00b9620 + 72a6638 commit 24a2eb7

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
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
Lines changed: 8 additions & 14 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,26 +61,19 @@ public bool 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-
try
64+
using (var inFile = File.OpenRead(iF))
65+
using (var cs = new CryptoStream(inFile, AES.CreateDecryptor(), CryptoStreamMode.Read))
66+
using (var outFile = File.Create(oF))
6467
{
65-
using (var inFile = File.OpenRead(iF))
66-
using (var cs = new CryptoStream(inFile, AES.CreateDecryptor(), CryptoStreamMode.Read))
67-
using (var outFile = File.Create(oF))
68-
{
6968

7069
sbyte data;
7170
while ((data = (sbyte)cs.ReadByte()) != -1)
7271
outFile.WriteByte((byte)data);
7372

74-
}
7573
}
76-
catch (CryptographicException)
77-
{
78-
return false;
79-
}
80-
return true;
74+
8175
}
8276

8377
}
8478
}
85-
}
79+
}

0 commit comments

Comments
 (0)