Skip to content

Commit

Permalink
Added more options to set for Aes and Rsa. Updated project to 4.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcidev committed Feb 4, 2017
1 parent 381269f commit a892187
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Arci.Networking.Tests/Arci.Networking.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Arci.Networking.Tests</RootNamespace>
<AssemblyName>Arci.Networking.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
4 changes: 2 additions & 2 deletions Arci.Networking.Tests/DataTests/GuidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 14 additions & 3 deletions Arci.Networking.Tests/EncryptionTests/RsaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 23 additions & 1 deletion Arci.Networking.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Arci.Networking/Arci.Networking.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Arci.Networking</RootNamespace>
<AssemblyName>Arci.Networking</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions Arci.Networking/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
9 changes: 9 additions & 0 deletions Arci.Networking/Security/AesEncryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public byte[] Decrypt(byte[] toDecode)
return decodedText;
}

/// <summary>
/// Sets aes padding mode
/// </summary>
/// <param name="mode">Padding mode to be used</param>
public void SetPaddingMode(PaddingMode mode)
{
aes.Padding = mode;
}

/// <summary>
/// Clears allocated resources
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions Arci.Networking/Security/RsaEncryptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class RsaEncryptor : IDisposable
{
private RSACryptoServiceProvider rsa;

/// <summary>
/// Sets true to use OAEP padding. Otherwise PKCS#1 v1.5 padding will be used
/// </summary>
public bool UseOAEPPadding { get; set; }

/// <summary>
/// Creates RSA instance. Used only for encryption
/// </summary>
Expand Down Expand Up @@ -42,7 +47,7 @@ public RsaEncryptor(RSAParameters rsaParams)
/// <returns>Encrypted data</returns>
public byte[] Encrypt(byte[] toEncrypt)
{
return rsa.Encrypt(toEncrypt, false);
return rsa.Encrypt(toEncrypt, UseOAEPPadding);
}

/// <summary>
Expand All @@ -52,7 +57,7 @@ public byte[] Encrypt(byte[] toEncrypt)
/// <returns>Decrypted data</returns>
public byte[] Decrypt(byte[] toDecrypt)
{
return rsa.Decrypt(toDecrypt, false);
return rsa.Decrypt(toDecrypt, UseOAEPPadding);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions ClientSample/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
</configuration>
6 changes: 2 additions & 4 deletions ClientSample/ClientSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClientSample</RootNamespace>
<AssemblyName>ClientSample</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -59,9 +60,6 @@
<Name>Shared</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
6 changes: 3 additions & 3 deletions ServerSample/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
</configuration>
3 changes: 2 additions & 1 deletion ServerSample/ServerSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ServerSample</RootNamespace>
<AssemblyName>ServerSample</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
3 changes: 2 additions & 1 deletion Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Shared</RootNamespace>
<AssemblyName>Shared</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down

0 comments on commit a892187

Please sign in to comment.