diff --git a/Arci.Networking.Tests/Arci.Networking.Tests.csproj b/Arci.Networking.Tests/Arci.Networking.Tests.csproj index c31c540..6a9ee01 100644 --- a/Arci.Networking.Tests/Arci.Networking.Tests.csproj +++ b/Arci.Networking.Tests/Arci.Networking.Tests.csproj @@ -8,7 +8,7 @@ Properties Arci.Networking.Tests Arci.Networking.Tests - v4.5.2 + v4.6.1 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -16,6 +16,7 @@ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest + true diff --git a/Arci.Networking.Tests/DataTests/GuidTests.cs b/Arci.Networking.Tests/DataTests/GuidTests.cs index 40f711f..1b3e0ce 100644 --- a/Arci.Networking.Tests/DataTests/GuidTests.cs +++ b/Arci.Networking.Tests/DataTests/GuidTests.cs @@ -53,9 +53,9 @@ public void WriteGuidTests() [TestMethod] public void MatchTests() { - var guid1 = guidValues[0]; + var guid1 = new Guid(guidValues[0]); var guid2 = guidValues[1]; - Assert.IsTrue(guidValues[0] == guid1); // Testing against different adress + Assert.IsTrue(guidValues[0] == guid1); // Testing against different adress but with same value Assert.IsTrue(guid2 != guid1); Assert.IsFalse(guid1 == null); Assert.IsFalse(null == guid2); diff --git a/Arci.Networking.Tests/EncryptionTests/RsaTests.cs b/Arci.Networking.Tests/EncryptionTests/RsaTests.cs index 9bea5e7..fbf5322 100644 --- a/Arci.Networking.Tests/EncryptionTests/RsaTests.cs +++ b/Arci.Networking.Tests/EncryptionTests/RsaTests.cs @@ -10,10 +10,21 @@ namespace Arci.Networking.Tests.EncryptionTests public class RsaTests { [TestMethod] - public void TestRsaEncryption() + public void TestPkcsPadding() { - var rsa = new RsaEncryptor(RSAKey.Modulus, RSAKey.PublicExponent); - var rsa2 = new RsaEncryptor(RSAKey.RsaParams); + TestEncryption(false); + } + + [TestMethod] + public void TestOEAPPadding() + { + TestEncryption(true); + } + + private void TestEncryption(bool useOAEPPadding) + { + var rsa = new RsaEncryptor(RSAKey.Modulus, RSAKey.PublicExponent) { UseOAEPPadding = useOAEPPadding }; + var rsa2 = new RsaEncryptor(RSAKey.RsaParams) { UseOAEPPadding = useOAEPPadding }; var value = Encoding.ASCII.GetBytes("Hello from unecrypted world"); var rsaEncryptedValue = rsa.Encrypt(value); diff --git a/Arci.Networking.sln b/Arci.Networking.sln index 68ae44d..9887d4b 100644 --- a/Arci.Networking.sln +++ b/Arci.Networking.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arci.Networking", "Arci.Networking\Arci.Networking.csproj", "{ED123DC2-0A2C-4B87-B723-23AAD065D518}" EndProject @@ -16,69 +16,91 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|ARM.ActiveCfg = Debug|Any CPU + {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|ARM.Build.0 = Debug|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|x64.ActiveCfg = Debug|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|x64.Build.0 = Debug|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|x86.ActiveCfg = Debug|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Debug|x86.Build.0 = Debug|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|Any CPU.ActiveCfg = Release|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|Any CPU.Build.0 = Release|Any CPU + {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|ARM.ActiveCfg = Release|Any CPU + {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|ARM.Build.0 = Release|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|x64.ActiveCfg = Release|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|x64.Build.0 = Release|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|x86.ActiveCfg = Release|Any CPU {ED123DC2-0A2C-4B87-B723-23AAD065D518}.Release|x86.Build.0 = Release|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|ARM.ActiveCfg = Debug|Any CPU + {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|ARM.Build.0 = Debug|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|x64.ActiveCfg = Debug|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|x64.Build.0 = Debug|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|x86.ActiveCfg = Debug|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Debug|x86.Build.0 = Debug|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|Any CPU.ActiveCfg = Release|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|Any CPU.Build.0 = Release|Any CPU + {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|ARM.ActiveCfg = Release|Any CPU + {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|ARM.Build.0 = Release|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|x64.ActiveCfg = Release|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|x64.Build.0 = Release|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|x86.ActiveCfg = Release|Any CPU {0E9D98C8-667E-4790-AF3C-2D485EBECAE5}.Release|x86.Build.0 = Release|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|ARM.ActiveCfg = Debug|Any CPU + {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|ARM.Build.0 = Debug|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|x64.ActiveCfg = Debug|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|x64.Build.0 = Debug|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|x86.ActiveCfg = Debug|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Debug|x86.Build.0 = Debug|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|Any CPU.Build.0 = Release|Any CPU + {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|ARM.ActiveCfg = Release|Any CPU + {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|ARM.Build.0 = Release|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|x64.ActiveCfg = Release|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|x64.Build.0 = Release|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|x86.ActiveCfg = Release|Any CPU {6699AA72-7048-4CAD-9E71-EB71425003EF}.Release|x86.Build.0 = Release|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|ARM.ActiveCfg = Debug|Any CPU + {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|ARM.Build.0 = Debug|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|x64.ActiveCfg = Debug|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|x64.Build.0 = Debug|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|x86.ActiveCfg = Debug|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Debug|x86.Build.0 = Debug|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|Any CPU.ActiveCfg = Release|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|Any CPU.Build.0 = Release|Any CPU + {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|ARM.ActiveCfg = Release|Any CPU + {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|ARM.Build.0 = Release|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|x64.ActiveCfg = Release|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|x64.Build.0 = Release|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|x86.ActiveCfg = Release|Any CPU {DDA1699F-C5DC-40B0-83CF-7343ABD4DF43}.Release|x86.Build.0 = Release|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|ARM.ActiveCfg = Debug|Any CPU + {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|ARM.Build.0 = Debug|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|x64.ActiveCfg = Debug|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|x64.Build.0 = Debug|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|x86.ActiveCfg = Debug|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Debug|x86.Build.0 = Debug|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|Any CPU.ActiveCfg = Release|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|Any CPU.Build.0 = Release|Any CPU + {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|ARM.ActiveCfg = Release|Any CPU + {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|ARM.Build.0 = Release|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|x64.ActiveCfg = Release|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|x64.Build.0 = Release|Any CPU {D62482C6-AF88-4BD9-97CB-CC22BDF1EA12}.Release|x86.ActiveCfg = Release|Any CPU diff --git a/Arci.Networking/Arci.Networking.csproj b/Arci.Networking/Arci.Networking.csproj index ec75491..ea8e447 100644 --- a/Arci.Networking/Arci.Networking.csproj +++ b/Arci.Networking/Arci.Networking.csproj @@ -9,7 +9,7 @@ Properties Arci.Networking Arci.Networking - v4.5 + v4.6.1 512 diff --git a/Arci.Networking/Client.cs b/Arci.Networking/Client.cs index 0eac92e..9077112 100644 --- a/Arci.Networking/Client.cs +++ b/Arci.Networking/Client.cs @@ -124,6 +124,7 @@ private byte[] readData() int length = stream.Read(data, 0, Packet.MaxPacketSize); if (length == 0) return null; + return data.Take(length).ToArray(); } } diff --git a/Arci.Networking/Security/AesEncryptor.cs b/Arci.Networking/Security/AesEncryptor.cs index a13104d..a932beb 100644 --- a/Arci.Networking/Security/AesEncryptor.cs +++ b/Arci.Networking/Security/AesEncryptor.cs @@ -124,6 +124,15 @@ public byte[] Decrypt(byte[] toDecode) return decodedText; } + /// + /// Sets aes padding mode + /// + /// Padding mode to be used + public void SetPaddingMode(PaddingMode mode) + { + aes.Padding = mode; + } + /// /// Clears allocated resources /// diff --git a/Arci.Networking/Security/RsaEncryptor.cs b/Arci.Networking/Security/RsaEncryptor.cs index 3c6af04..fdefeb5 100644 --- a/Arci.Networking/Security/RsaEncryptor.cs +++ b/Arci.Networking/Security/RsaEncryptor.cs @@ -10,6 +10,11 @@ public class RsaEncryptor : IDisposable { private RSACryptoServiceProvider rsa; + /// + /// Sets true to use OAEP padding. Otherwise PKCS#1 v1.5 padding will be used + /// + public bool UseOAEPPadding { get; set; } + /// /// Creates RSA instance. Used only for encryption /// @@ -42,7 +47,7 @@ public RsaEncryptor(RSAParameters rsaParams) /// Encrypted data public byte[] Encrypt(byte[] toEncrypt) { - return rsa.Encrypt(toEncrypt, false); + return rsa.Encrypt(toEncrypt, UseOAEPPadding); } /// @@ -52,7 +57,7 @@ public byte[] Encrypt(byte[] toEncrypt) /// Decrypted data public byte[] Decrypt(byte[] toDecrypt) { - return rsa.Decrypt(toDecrypt, false); + return rsa.Decrypt(toDecrypt, UseOAEPPadding); } /// diff --git a/ClientSample/App.config b/ClientSample/App.config index 88fa402..bae5d6d 100644 --- a/ClientSample/App.config +++ b/ClientSample/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/ClientSample/ClientSample.csproj b/ClientSample/ClientSample.csproj index 7d20db5..63f1aef 100644 --- a/ClientSample/ClientSample.csproj +++ b/ClientSample/ClientSample.csproj @@ -9,9 +9,10 @@ Properties ClientSample ClientSample - v4.5.2 + v4.6.1 512 true + AnyCPU @@ -59,9 +60,6 @@ Shared - - -