From 0667a288fb42743141ea1a5a866aa48585774619 Mon Sep 17 00:00:00 2001 From: Tom-Kuhn Date: Wed, 18 Jun 2014 14:01:23 +0100 Subject: [PATCH] Added sample projects and updated readme --- README.md | 4 + SimpleAesEncryption.sln | 16 ++++ .../CastleWithCustomConfigSection/App.config | 14 ++++ .../CastleWithCustomConfigSection.csproj | 84 +++++++++++++++++++ .../EncryptionSampleManager.cs | 26 ++++++ .../IExecuteSample.cs | 13 +++ .../CastleWithCustomConfigSection/Program.cs | 35 ++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ .../SampleCastleInstaller.cs | 29 +++++++ .../packages.config | 5 ++ sample/SimpleExample/App.config | 14 ++++ sample/SimpleExample/Program.cs | 36 ++++++++ .../SimpleExample/Properties/AssemblyInfo.cs | 36 ++++++++ sample/SimpleExample/SimpleExample.csproj | 65 ++++++++++++++ 14 files changed, 413 insertions(+) create mode 100644 sample/CastleWithCustomConfigSection/App.config create mode 100644 sample/CastleWithCustomConfigSection/CastleWithCustomConfigSection.csproj create mode 100644 sample/CastleWithCustomConfigSection/EncryptionSampleManager.cs create mode 100644 sample/CastleWithCustomConfigSection/IExecuteSample.cs create mode 100644 sample/CastleWithCustomConfigSection/Program.cs create mode 100644 sample/CastleWithCustomConfigSection/Properties/AssemblyInfo.cs create mode 100644 sample/CastleWithCustomConfigSection/SampleCastleInstaller.cs create mode 100644 sample/CastleWithCustomConfigSection/packages.config create mode 100644 sample/SimpleExample/App.config create mode 100644 sample/SimpleExample/Program.cs create mode 100644 sample/SimpleExample/Properties/AssemblyInfo.cs create mode 100644 sample/SimpleExample/SimpleExample.csproj diff --git a/README.md b/README.md index cb79ebc..a09ff26 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/SimpleAesEncryption.sln b/SimpleAesEncryption.sln index fdfa8d4..a15eff9 100644 --- a/SimpleAesEncryption.sln +++ b/SimpleAesEncryption.sln @@ -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 @@ -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 @@ -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 diff --git a/sample/CastleWithCustomConfigSection/App.config b/sample/CastleWithCustomConfigSection/App.config new file mode 100644 index 0000000..a1fe3eb --- /dev/null +++ b/sample/CastleWithCustomConfigSection/App.config @@ -0,0 +1,14 @@ + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/sample/CastleWithCustomConfigSection/CastleWithCustomConfigSection.csproj b/sample/CastleWithCustomConfigSection/CastleWithCustomConfigSection.csproj new file mode 100644 index 0000000..182b3b7 --- /dev/null +++ b/sample/CastleWithCustomConfigSection/CastleWithCustomConfigSection.csproj @@ -0,0 +1,84 @@ + + + + + Debug + AnyCPU + {20E15878-B343-4C4B-AD5B-684DE4E30BF3} + Exe + Properties + ArtisanCode.SimpleAes.CastleWithCustomConfigSection + CastleWithCustomConfigSection + v4.5.1 + 512 + true + ..\..\ + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll + + + ..\..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll + + + + + + + + + + + + + + + + + + + + + + + {e94e1d6c-7182-491d-a5c4-79b1be3dc48a} + SimpleAesEncryption + + + + + + + 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}. + + + + + \ No newline at end of file diff --git a/sample/CastleWithCustomConfigSection/EncryptionSampleManager.cs b/sample/CastleWithCustomConfigSection/EncryptionSampleManager.cs new file mode 100644 index 0000000..580f3d9 --- /dev/null +++ b/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); + } + } +} diff --git a/sample/CastleWithCustomConfigSection/IExecuteSample.cs b/sample/CastleWithCustomConfigSection/IExecuteSample.cs new file mode 100644 index 0000000..869825a --- /dev/null +++ b/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); + } +} diff --git a/sample/CastleWithCustomConfigSection/Program.cs b/sample/CastleWithCustomConfigSection/Program.cs new file mode 100644 index 0000000..278a1e0 --- /dev/null +++ b/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(); + sampleManager.ExecuteSample(input); + + Console.WriteLine(); + Console.WriteLine("Please press any key to exit."); + Console.ReadKey(); + } + } +} diff --git a/sample/CastleWithCustomConfigSection/Properties/AssemblyInfo.cs b/sample/CastleWithCustomConfigSection/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0dd49fb --- /dev/null +++ b/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")] diff --git a/sample/CastleWithCustomConfigSection/SampleCastleInstaller.cs b/sample/CastleWithCustomConfigSection/SampleCastleInstaller.cs new file mode 100644 index 0000000..4fe890e --- /dev/null +++ b/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() + .ImplementedBy() + .DependsOn(Dependency.OnValue("configurationSectionName", "CustomSimpleAESConfigurationSectionName"))); // use custom config section + + container.Register( + Component.For() + .ImplementedBy() + .DependsOn(Dependency.OnValue("configurationSectionName", "CustomSimpleAESConfigurationSectionName"))); // use custom config section + + container.Register(Component.For().ImplementedBy()); + } + } +} diff --git a/sample/CastleWithCustomConfigSection/packages.config b/sample/CastleWithCustomConfigSection/packages.config new file mode 100644 index 0000000..b93e4a4 --- /dev/null +++ b/sample/CastleWithCustomConfigSection/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sample/SimpleExample/App.config b/sample/SimpleExample/App.config new file mode 100644 index 0000000..54d9902 --- /dev/null +++ b/sample/SimpleExample/App.config @@ -0,0 +1,14 @@ + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/sample/SimpleExample/Program.cs b/sample/SimpleExample/Program.cs new file mode 100644 index 0000000..0305174 --- /dev/null +++ b/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(); + } + } +} diff --git a/sample/SimpleExample/Properties/AssemblyInfo.cs b/sample/SimpleExample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cefe732 --- /dev/null +++ b/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")] diff --git a/sample/SimpleExample/SimpleExample.csproj b/sample/SimpleExample/SimpleExample.csproj new file mode 100644 index 0000000..37da32a --- /dev/null +++ b/sample/SimpleExample/SimpleExample.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {47B4F4B7-BD6B-4792-8CA6-153EA4FE772B} + Exe + Properties + ArtisanCode.SimpleAes.SimpleExample + SimpleExample + v4.5.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {e94e1d6c-7182-491d-a5c4-79b1be3dc48a} + SimpleAesEncryption + + + + + \ No newline at end of file