Skip to content

Commit

Permalink
Added sample projects and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Kuhn committed Jun 18, 2014
1 parent 55aa2cc commit 0667a28
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -74,4 +74,8 @@ string Decrypt(string cypherText);

You can create instances of ```RijndaelMessageEncryptor``` and ```RijndaelMessageDecryptor``` directly by using the relevent constructors OR, you can use your favourite Dependency Injection container to manage the instansiation for you.

For an idea of how to use this library, please refer to the sample projects:
* Simple Example - shows how to use the library in its simplest form
* Integration with Castle whilst using a custom configuration section name to contain the encryption information

That's all you need to know in order to start encrypting and decrypting to your heart's content!
16 changes: 16 additions & 0 deletions SimpleAesEncryption.sln
Expand Up @@ -27,6 +27,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{65354631-B9A7-4B93-9889-6623B06B9230}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExample", "sample\SimpleExample\SimpleExample.csproj", "{47B4F4B7-BD6B-4792-8CA6-153EA4FE772B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CastleWithCustomConfigSection", "sample\CastleWithCustomConfigSection\CastleWithCustomConfigSection.csproj", "{20E15878-B343-4C4B-AD5B-684DE4E30BF3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -45,6 +51,14 @@ Global
{9E3D5C62-B5BA-4213-A4DB-CB523528713C}.Debug|Any CPU.Build.0 = Release|Any CPU
{9E3D5C62-B5BA-4213-A4DB-CB523528713C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E3D5C62-B5BA-4213-A4DB-CB523528713C}.Release|Any CPU.Build.0 = Release|Any CPU
{47B4F4B7-BD6B-4792-8CA6-153EA4FE772B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47B4F4B7-BD6B-4792-8CA6-153EA4FE772B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47B4F4B7-BD6B-4792-8CA6-153EA4FE772B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47B4F4B7-BD6B-4792-8CA6-153EA4FE772B}.Release|Any CPU.Build.0 = Release|Any CPU
{20E15878-B343-4C4B-AD5B-684DE4E30BF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20E15878-B343-4C4B-AD5B-684DE4E30BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20E15878-B343-4C4B-AD5B-684DE4E30BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20E15878-B343-4C4B-AD5B-684DE4E30BF3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -53,5 +67,7 @@ Global
{E94E1D6C-7182-491D-A5C4-79B1BE3DC48A} = {C6DD140B-413D-4023-8EA6-50F9871CA803}
{9E3D5C62-B5BA-4213-A4DB-CB523528713C} = {C6DD140B-413D-4023-8EA6-50F9871CA803}
{2829C552-8959-4E0C-8994-9D6800922CC9} = {E0D81C72-5893-4720-BE6B-74834EF19FD5}
{47B4F4B7-BD6B-4792-8CA6-153EA4FE772B} = {65354631-B9A7-4B93-9889-6623B06B9230}
{20E15878-B343-4C4B-AD5B-684DE4E30BF3} = {65354631-B9A7-4B93-9889-6623B06B9230}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions sample/CastleWithCustomConfigSection/App.config
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="CustomSimpleAESConfigurationSectionName" type="ArtisanCode.SimpleAesEncryption.SimpleAesEncryptionConfiguration, ArtisanCode.SimpleAesEncryption"/>
</configSections>

<CustomSimpleAESConfigurationSectionName>
<EncryptionKey KeySize="256" Key="GRE5sAmmndnu0t3h1+OzMNfrGHoVn2mdy44qISfVJqs="/>
</CustomSimpleAESConfigurationSectionName>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{20E15878-B343-4C4B-AD5B-684DE4E30BF3}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ArtisanCode.SimpleAes.CastleWithCustomConfigSection</RootNamespace>
<AssemblyName>CastleWithCustomConfigSection</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core">
<HintPath>..\..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.Windsor">
<HintPath>..\..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EncryptionSampleManager.cs" />
<Compile Include="IExecuteSample.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SampleCastleInstaller.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SimpleAesEncryption\SimpleAesEncryption.csproj">
<Project>{e94e1d6c-7182-491d-a5c4-79b1be3dc48a}</Project>
<Name>SimpleAesEncryption</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
26 changes: 26 additions & 0 deletions sample/CastleWithCustomConfigSection/EncryptionSampleManager.cs
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArtisanCode.SimpleAesEncryption;

namespace ArtisanCode.SimpleAes.CastleWithCustomConfigSection
{
public class EncryptionSampleManager: IExecuteSample
{
public IMessageEncryptor Encryptor { get; set; }
public IMessageDecryptor Decryptor { get; set; }

public void ExecuteSample(string input)
{
var cyphertext = Encryptor.Encrypt(input);

var plaintext = Decryptor.Decrypt(cyphertext);

Console.WriteLine("Input:" + input);
Console.WriteLine("Cyphertext:" + cyphertext);
Console.WriteLine("Plaintext:" + plaintext);
}
}
}
13 changes: 13 additions & 0 deletions sample/CastleWithCustomConfigSection/IExecuteSample.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArtisanCode.SimpleAes.CastleWithCustomConfigSection
{
public interface IExecuteSample
{
void ExecuteSample(string input);
}
}
35 changes: 35 additions & 0 deletions sample/CastleWithCustomConfigSection/Program.cs
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.Windsor;

namespace ArtisanCode.SimpleAes.CastleWithCustomConfigSection
{
class Program
{
static void Main(string[] args)
{
var input = "Hello World!";

if (args.Length > 0)
{
input = args[0];
}

var Container = new WindsorContainer();

// Configure Castle
Container.Install(new SampleCastleInstaller());

// Resolve sample manager and execute
var sampleManager = Container.Resolve<IExecuteSample>();
sampleManager.ExecuteSample(input);

Console.WriteLine();
Console.WriteLine("Please press any key to exit.");
Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions sample/CastleWithCustomConfigSection/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CastleWithCustomConfigSection")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CastleWithCustomConfigSection")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a7b9b18f-8540-40fd-8379-b50eb189d708")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
29 changes: 29 additions & 0 deletions sample/CastleWithCustomConfigSection/SampleCastleInstaller.cs
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.Windsor;
using Castle.MicroKernel.Registration;
using ArtisanCode.SimpleAesEncryption;

namespace ArtisanCode.SimpleAes.CastleWithCustomConfigSection
{
public class SampleCastleInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
container.Register(
Component.For<IMessageEncryptor>()
.ImplementedBy<RijndaelMessageEncryptor>()
.DependsOn(Dependency.OnValue("configurationSectionName", "CustomSimpleAESConfigurationSectionName"))); // use custom config section

container.Register(
Component.For<IMessageDecryptor>()
.ImplementedBy<RijndaelMessageDecryptor>()
.DependsOn(Dependency.OnValue("configurationSectionName", "CustomSimpleAESConfigurationSectionName"))); // use custom config section

container.Register(Component.For<IExecuteSample>().ImplementedBy<EncryptionSampleManager>());
}
}
}
5 changes: 5 additions & 0 deletions sample/CastleWithCustomConfigSection/packages.config
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.0" targetFramework="net451" />
<package id="Castle.Windsor" version="3.3.0" targetFramework="net451" />
</packages>
14 changes: 14 additions & 0 deletions sample/SimpleExample/App.config
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MessageEncryption" type="ArtisanCode.SimpleAesEncryption.SimpleAesEncryptionConfiguration, ArtisanCode.SimpleAesEncryption"/>
</configSections>

<MessageEncryption>
<EncryptionKey KeySize="256" Key="GRE5sAmmndnu0t3h1+OzMNfrGHoVn2mdy44qISfVJqs="/>
</MessageEncryption>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
36 changes: 36 additions & 0 deletions sample/SimpleExample/Program.cs
@@ -0,0 +1,36 @@
using ArtisanCode.SimpleAesEncryption;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArtisanCode.SimpleAes.SimpleExample
{
class Program
{
static void Main(string[] args)
{
var input = "Hello World!";

if(args.Length > 0)
{
input = args[0];
}

var encryptor = new RijndaelMessageEncryptor();
var cyphertext = encryptor.Encrypt(input);

var decryptor = new RijndaelMessageDecryptor();
var plaintext = decryptor.Decrypt(cyphertext);

Console.WriteLine("Input:" + input);
Console.WriteLine("Cyphertext:" + cyphertext);
Console.WriteLine("Plaintext:" + plaintext);

Console.WriteLine();
Console.WriteLine("Please press any key to exit.");
Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions sample/SimpleExample/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SimpleExample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleExample")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3862e46f-3833-422d-a97b-a46d20a9000e")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 0667a28

Please sign in to comment.