Skip to content

Commit cde5555

Browse files
committed
Added beginning of HMAC verification. Non working
1 parent c6ab693 commit cde5555

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

docs/HeaderSpec.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
-ITERATIONS:(iterations here)
1717
}
1818
19-
-KEYVERIFICATIONHASH:(hash here, None)
20-
{
21-
-HASHALGO:(PBKDF2, SHA256, bcrypt),
22-
-ITERATIONS:(iterations here)
23-
}
24-
2519
-ENCRYPTMODE:(AES, RSA, etc)
2620
{
2721
-AESMODE:(ECB, CBC, CFB, CTR),
@@ -41,16 +35,13 @@
4135
| Argument | Meaning | Values |
4236
| ------------------------------------------------------ |-------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
4337
| <a href="#HMAC">HMAC</a> | The verification hash used to confirm the file hasn't changed | 128 - 512 bit byte array (16-64 bytes) |
44-
| <a href="#KEYVERIFICATIONHASH">KEYVERIFICATIONHASH</a> | A hash of the key to verify if the password is correct | 128 - 512 bit byte array (16-64 bytes) |
4538
| <a href="#ENCRYPTMODE">ENCRYPTMODE</a> | A byte representing the encryption type | A string in the table of <a href="#ENCRYPTMODE">ENCRYPTMODE</a> page, and the (undefined ATM -- TODO) enumeration |
4639
| <a href="IV">IV</a> | The initialization vector used to start the encryption | 128 - 512 bit byte array (16-64 bytes) |
4740

4841

4942
### <p id="HMAC">HMAC</p>
5043

51-
* The HMAC (Hash Message Authentication Code)
52-
53-
### <p id="KEYVERIFICATIONHASH">KEYVERIFICATIONHASH</p>
44+
The HMAC (Hash Message Authentication Code) is a hash that is used to verify the message hasn't been tampered with. The HMAC is the hashed value of the encrypted message. The receiver can re-hash the received message to verify the message hasn't been tampered with. **IMPORTANT: HMAC construction MUST be actual HMAC algorithm, not just hashing. See [this](https://en.wikipedia.org/wiki/HMAC#Implementation) for details ****
5445

5546
### <p id ="ENCRYPTMODE">ENCRYPTMODE</P>
5647

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.IO;
3+
using System.Security.Cryptography;
4+
5+
namespace Encryption_App
6+
{
7+
class MessageAuthenticator
8+
{
9+
public void VerifyHMACFile(byte[] data, byte[] key)
10+
{
11+
byte[] hashKey;
12+
13+
using (var hmac = new HMACSHA384(key))
14+
{
15+
if (key.Length > hmac.InputBlockSize)
16+
{
17+
hashKey = hmac.ComputeHash(data);
18+
}
19+
}
20+
}
21+
22+
public void VerifyHMACFile(byte[] data, byte[] key, Type TypeOfHash)
23+
{
24+
HMAC hmac;
25+
if (TypeOfHash.IsSubclassOf(typeof(HMAC)))
26+
{
27+
hmac = (HMAC)Activator.CreateInstance(TypeOfHash);
28+
}
29+
else
30+
{
31+
throw new ArgumentException("TypeOfHash is not a derivative of \"System.Security.Cryptorgaphy.HMAC\"");
32+
}
33+
}
34+
}
35+
}

src/EncryptionApp.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
<SubType>Designer</SubType>
6161
</Page>
6262
<Compile Include="Backend\AESCryptoManager.cs" />
63-
<Compile Include="UI\App.xaml.cs" >
63+
<Compile Include="Backend\MessageAuthenticator.cs" />
64+
<Compile Include="UI\App.xaml.cs">
6465
<DependentUpon>App.xaml</DependentUpon>
6566
<SubType>Code</SubType>
6667
</Compile>
@@ -97,4 +98,4 @@
9798
</ItemGroup>
9899
<ItemGroup />
99100
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100-
</Project>
101+
</Project>

0 commit comments

Comments
 (0)