Explorar el Código

Common:

      27.12.2019 v.1.0.0.7
      Fix
      - Fix Secure class to work with empty strings
Dalibor Votruba hace 6 años
padre
commit
2066dfa543

+ 59 - 0
@Workbench/@Workbench.csproj

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" 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>{60DDDF9B-507A-4665-8A5B-1F670005727F}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>_Workbench</RootNamespace>
+    <AssemblyName>%40Workbench</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <Deterministic>true</Deterministic>
+  </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="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.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Common\Common.csproj">
+      <Project>{6d9348fb-8c3d-4dfd-949b-414fc6bf2a22}</Project>
+      <Name>Common</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 6 - 0
@Workbench/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+    </startup>
+</configuration>

+ 19 - 0
@Workbench/Program.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Quadarax.Foundation.Common.Security;
+
+namespace _Workbench
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            var plain = "foforotopo";
+            var result = Secure.Encrypt(plain);
+            Console.WriteLine(result);
+        }
+    }
+}

+ 36 - 0
@Workbench/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("@Workbench")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("@Workbench")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[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("60dddf9b-507a-4665-8a5b-1f670005727f")]
+
+// 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")]

+ 6 - 0
Common/Common.sln

@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.902
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common.csproj", "{6D9348FB-8C3D-4DFD-949B-414FC6BF2A22}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "@Workbench", "..\@Workbench\@Workbench.csproj", "{60DDDF9B-507A-4665-8A5B-1F670005727F}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
 		{6D9348FB-8C3D-4DFD-949B-414FC6BF2A22}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{6D9348FB-8C3D-4DFD-949B-414FC6BF2A22}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{6D9348FB-8C3D-4DFD-949B-414FC6BF2A22}.Release|Any CPU.Build.0 = Release|Any CPU
+		{60DDDF9B-507A-4665-8A5B-1F670005727F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{60DDDF9B-507A-4665-8A5B-1F670005727F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{60DDDF9B-507A-4665-8A5B-1F670005727F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{60DDDF9B-507A-4665-8A5B-1F670005727F}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 2
Common/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // 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.6")]
-[assembly: AssemblyFileVersion("1.0.0.6")]
+[assembly: AssemblyVersion("1.0.0.7")]
+[assembly: AssemblyFileVersion("1.0.0.7")]

+ 4 - 6
Common/QDR.FND.Common.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Quadarax.Foundation.Common</id>
-    <version>1.0.0.6</version>
+    <version>1.0.0.7</version>
     <title>Quadarax.Foundation.Common</title>
     <authors>Dalibor Votruba, Quadarax</authors>
     <owners>Dalibor Votruba</owners>
@@ -11,11 +11,9 @@
     <requireLicenseAcceptance>false</requireLicenseAcceptance>
     <description>Implementations of simple patterns and misc. extensions.</description>
     <releaseNotes>
-      27.12.2019 v.1.0.0.6
-      New
-      - Add Singleton implementation
-      - Add WeakReference generic pattern
-      - Add VolatileCache implementation
+      27.12.2019 v.1.0.0.7
+      Fix
+      - Fix Secure class to work with empty strings
     </releaseNotes>
     <copyright>Copyright (c) 2020 Quadarax</copyright>
     <tags>quadarax, foundation, common, qdr, fnd, library, extensions</tags>

+ 4 - 0
Common/ReleaseNote.txt

@@ -1,3 +1,7 @@
+27.12.2019 v.1.0.0.7
+Fix
+ - Fix Secure class to work with empty strings
+
 27.12.2019 v.1.0.0.6
 New
  - Add Singleton implementation

+ 26 - 5
Common/Security/Secure.cs

@@ -7,13 +7,28 @@ namespace Quadarax.Foundation.Common.Security
 {
     public static class Secure
     {
-        static string _passwordHash = "OmMC:7i%+o.MlIeg`kRcv:R3haPyx|#vuM,G,oB1n=IBUG'!M6";
-        static string _saltKey = "vo:Y:pWYcS\"*m@^6R\\O#$eSg!,23H\\R8KfIi\\u1IED91TE0J#~";
-        static string _vIKey = "@!PYn,b=t4\\%`Am`z!ubwE1H2Ek1?*R&,6cF:f1mZJ1dxB&DZH";
+        /*
+        static string _passwordHash = "/:-s*oQ9VG~!]}))ud?ar*(5RanaWm{LHO-7Ncr[lvXGhB0=./raTYVGhO)n$ioE:tH1-TV.h57J+V-K+nVONHvAGeFa+0;R,`LUzqG&KI%-JQO6x>_/L'[sP2Cuz{z?9ch<2F~Cw@}@LNMpmv'viP+YHb}Z%.#dT*`5:nabn5n;8g1Tm<@,Zk(F9m{[s17*lc*P^}}HD,Mh]wnwaZfvYA`uCQ)Or&~cLy6wlYd_fw?ljr5i]l!UFhC'[sTbOaru";
+        static string _saltKey =      "Unx.Y16ju9K)!@uA>9#DVxan%Wr,&c~[2q?T}Q'~XBweCgtvL7+&zv%(9uQxn#gnDYE_(IgQ%sUK-!n+{d-{vBhLXXbUJ$G]SQiXt.#S(WS=oQPTYU|%{o)fN=90/KgYfo&5$&hL}JAu8.+2]kPoRM1Rr&=prDKBpahWjjr?q;.`_8hrjJ]Y-ap88N$FcR,%SkyV)(ssdg1~A&3i?|n`yoJPBMy$];Q=%3b/^}|6<Dj!Agna3K;27gCl2Y9*vhqH";
+        static string _vIKey =        "29T|l'6$&Z}(NpQ8]~d1U-kVO@ot8)&w$uf&UsDBKfcB_1rQ0'5H+w.EHKlS5)14AiBa(Kg4dmOpfan0s%eGwxy$1:|lRrkBLZJndV/l3;`W(Plx[n88TD]'kk@wYl_dA7#DP2|]V03~mkRh!8{$&bUTF585Zjb@B}d'2jo7n:7VA-e|X!nf7e$xP`dBh`DAE=Q~_TOVH;gJDK}Q>f@q.u&#2yOK=!F,$/{F5BxGvqUt$?ry0AmKNOH:y}XJq_x_";
+        */
+        private static string _passwordHash = "Vk&G#lG}vv@5S55x";
+        private static string _saltKey = "vzb4[}[L%<='(U!n";
+        private static string _vIKey = "&C%:gIt<P-|%nA45";
 
 
         public static void SetProperties(string passwordHash, string saltKey, string vIKey)
         {
+            if (passwordHash.Length != 16)
+                throw new ArgumentOutOfRangeException(nameof(passwordHash),"Value must have 16 chars.");
+
+            if (saltKey.Length != 16)
+                throw new ArgumentOutOfRangeException(nameof(saltKey),"Value must have 16 chars.");
+
+            if (vIKey.Length != 16)
+                throw new ArgumentOutOfRangeException(nameof(vIKey),"Value must have 16 chars.");
+
+
             _passwordHash = passwordHash;
             _saltKey = saltKey;
             _vIKey = vIKey;
@@ -21,10 +36,13 @@ namespace Quadarax.Foundation.Common.Security
 
         public static string Encrypt(string plainText)
         {
+            if (string.IsNullOrEmpty(plainText))
+                return string.Empty;
+
             var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
 
-            var keyBytes = new Rfc2898DeriveBytes(_passwordHash, Encoding.ASCII.GetBytes(_saltKey)).GetBytes(256 / 8);
-            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
+            var keyBytes = new Rfc2898DeriveBytes(_passwordHash, Encoding.UTF8.GetBytes(_saltKey)).GetBytes(256/8);
+            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros};
             var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(_vIKey));
 			
             byte[] cipherTextBytes;
@@ -45,6 +63,9 @@ namespace Quadarax.Foundation.Common.Security
 
         public static string Decrypt(string encryptedText)
         {
+            if (string.IsNullOrEmpty(encryptedText))
+                return string.Empty;
+
             var cipherTextBytes = Convert.FromBase64String(encryptedText);
             var keyBytes = new Rfc2898DeriveBytes(_passwordHash, Encoding.ASCII.GetBytes(_saltKey)).GetBytes(256 / 8);
             var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.None };