Skip to content

Commit 86b2391

Browse files
authored
Merge pull request #14 from johnkellyoxford/dev
Dev
2 parents 3103aeb + 41866ca commit 86b2391

File tree

6 files changed

+67
-12
lines changed

6 files changed

+67
-12
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

docs/HeaderSpec.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Header specification
2+
3+
## Header format
4+
5+
* The items in the header are as followed (square brackets representing the start and end of the header, anything in braces is related to the previous option). Newlines and tabs are not true, but simply for formatting:
6+
7+
```
8+
[
9+
-HMAC:(hash here, None)
10+
{ -HASHALGO:(PBKDF2, SHA256, bcrypt) }
11+
{ -ITERATIONS:(iterations here) }
12+
-KEYVERIFICATIONHASH:(hash here, None)
13+
{ -HASHALGO:(PBKDF2, SHA256, bcrypt) }
14+
{ -ITERATIONS:(iterations here) }
15+
-ENCRYPTMODE:(AES, RSA, etc)
16+
{{-AESMODE:(ECB, CBC, CFB, CTR),
17+
-ECCMODE:(different curves fo here)}
18+
-KEYSIZE: (int)
19+
-BLOCKSIZE: (int)
20+
}
21+
{ -IV:(IV here) }
22+
]
23+
```
24+
25+
## Header items
26+
27+
| Argument | Meaning | Values|
28+
| ------------- |-------------| ----- |
29+
| <a href="#HMAC">HMAC</a> | The verification hash used to confirm the file hasn't changed | 128 - 512 bit byte array (16-64 bytes) |
30+
| [KEYVERIFICATIONHASH](#KEYVERIFICATIONHASH) | A hash of the key to verify if the password is correct | 128 - 512 bit byte array (16-64 bytes) |
31+
| [ENCRYPTMODE](#ENCRYPTMODE) | A byte representing the encryption type | A number in the table of [ENCRYPTMODE](#ENCRYPTMODE) page |
32+
33+
### <p id="HMAC">HMAC</p>
34+
35+
### KEYVERIFICATIONHASH

docs/ignore.txt

Whitespace-only changes.
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void AES_Encrypt(string iF, string oF, byte[] passwordBytes)
3939

4040
}
4141

42-
public void AES_Decrypt(string iF, string oF, byte[] passwordBytes)
42+
public bool AES_Decrypt(string iF, string oF, byte[] passwordBytes)
4343
{
4444

4545
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
@@ -60,19 +60,28 @@ public void AES_Decrypt(string iF, string oF, byte[] passwordBytes)
6060
AES.Key = key.GetBytes(AES.KeySize / 8);
6161
AES.IV = key.GetBytes(AES.BlockSize / 8);
6262

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))
63+
try
6664
{
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+
{
6769

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

74+
}
7275
}
73-
76+
catch (CryptographicException)
77+
{
78+
return false;
79+
}
80+
return true;
7481
}
7582

7683
}
84+
85+
}
7786
}
78-
}
87+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Generator>MSBuild:Compile</Generator>
6060
<SubType>Designer</SubType>
6161
</Page>
62+
<Compile Include="Backend\AESCryptoManager.cs" />
6263
<Compile Include="Backend\Encryptor.cs" />
6364
<Compile Include="UI\App.xaml.cs">
6465
<DependentUpon>App.xaml</DependentUpon>

src/UI/MainWindow.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ private void Encrypt_Click(object sender, RoutedEventArgs e)
7979
string pwd = InpTxtBox.Text;
8080
string ofilePath = FileTxtBox.Text;
8181
AESCryptoManager encryptor = new AESCryptoManager();
82-
encryptor.AES_Encrypt(ofilePath, @"D:\johnk\Documents\pnp.txt", Encoding.UTF8.GetBytes(pwd));
82+
encryptor.AES_Encrypt(ofilePath, System.IO.Path.GetTempPath() + "tempdata.ini", Encoding.UTF8.GetBytes(pwd));
83+
File.Copy(System.IO.Path.GetTempPath() + "tempdata.ini", ofilePath, true);
8384
}
8485

8586
private void Decrypt_Click(object sender, RoutedEventArgs e)
@@ -90,8 +91,17 @@ private void Decrypt_Click(object sender, RoutedEventArgs e)
9091
FileInfo f = new FileInfo(ofilePath);
9192

9293
AESCryptoManager decryptor = new AESCryptoManager();
94+
bool worked = decryptor.AES_Decrypt(ofilePath, System.IO.Path.GetTempPath() + "tempdata.ini", Encoding.UTF8.GetBytes(pwd)); ;
95+
if (worked) { File.Copy(System.IO.Path.GetTempPath() + "tempdata.ini", ofilePath, true); }
9396

94-
decryptor.AES_Decrypt(ofilePath, @"D:\johnk\Documents\btec.txt", Encoding.UTF8.GetBytes(pwd));
97+
if (!worked)
98+
{
99+
MessageBox.Show("Wrong Password");
100+
}
101+
else
102+
{
103+
MessageBox.Show("Successfully Decrypted");
104+
}
95105
}
96106
}
97107
}

0 commit comments

Comments
 (0)