Skip to content

Commit

Permalink
Added and tested MAC keyed hashers like HMAC-SHA256 or MAC-3DES.
Browse files Browse the repository at this point in the history
Added and tested a MAC key importing/exporting utility "MacKey" in the style of EncryptedKey or ProtectedKey.
  • Loading branch information
vmelamed committed Jan 4, 2016
1 parent a1ab74f commit 910dd6f
Show file tree
Hide file tree
Showing 24 changed files with 1,117 additions and 341 deletions.
2 changes: 1 addition & 1 deletion Aspects/Diagnostics/NuGet/ObjectDumper.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<licenseUrl>https://aspectobjectdumper.codeplex.com/license</licenseUrl>
<projectUrl>https://aspectobjectdumper.codeplex.com/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright © vm 2013-2015</copyright>
<copyright>Copyright © vm 2013-2016</copyright>
<dependencies>
<dependency id="CommonServiceLocator"
version="1.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<licenseUrl>https://github.com/vmelamed/vm/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/vmelamed/vm/tree/master/Aspects/Linq/Expressions/Serialization</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright © vm 2013-2015</copyright>
<copyright>Copyright © vm 2013-2016</copyright>
<dependencies>
</dependencies>
<tags>.net LINQ expression tree serialization XML aspects</tags>
Expand Down
2 changes: 1 addition & 1 deletion Aspects/NuGet/vm.Aspects.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<licenseUrl>https://github.com/vmelamed/vm/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/vmelamed/vm/tree/master/Aspects</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright © vm 2013-2015</copyright>
<copyright>Copyright © vm 2013-2016</copyright>
<dependencies>
<dependency id="CommonServiceLocator"
version="1.3" />
Expand Down
164 changes: 2 additions & 162 deletions Aspects/Security/Cryptography/Ciphers/EncryptedKey/EncryptedKey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,171 +145,10 @@
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\..\..\..\Common Items\vm.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug40|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug40\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET40</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>..\..\..\..\..\Common Items\vmAllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug40\EncryptedKey.XML</DocumentationFile>
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
<CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
<CodeContractsNonNullObligations>True</CodeContractsNonNullObligations>
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
<CodeContractsEnumObligations>True</CodeContractsEnumObligations>
<CodeContractsRedundantAssumptions>True</CodeContractsRedundantAssumptions>
<CodeContractsAssertsToContractsCheckBox>True</CodeContractsAssertsToContractsCheckBox>
<CodeContractsRedundantTests>True</CodeContractsRedundantTests>
<CodeContractsMissingPublicRequiresAsWarnings>True</CodeContractsMissingPublicRequiresAsWarnings>
<CodeContractsMissingPublicEnsuresAsWarnings>True</CodeContractsMissingPublicEnsuresAsWarnings>
<CodeContractsInferRequires>True</CodeContractsInferRequires>
<CodeContractsInferEnsures>True</CodeContractsInferEnsures>
<CodeContractsInferEnsuresAutoProperties>True</CodeContractsInferEnsuresAutoProperties>
<CodeContractsInferObjectInvariants>True</CodeContractsInferObjectInvariants>
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
<CodeContractsSuggestAssumptionsForCallees>False</CodeContractsSuggestAssumptionsForCallees>
<CodeContractsSuggestRequires>True</CodeContractsSuggestRequires>
<CodeContractsNecessaryEnsures>True</CodeContractsNecessaryEnsures>
<CodeContractsSuggestObjectInvariants>True</CodeContractsSuggestObjectInvariants>
<CodeContractsSuggestReadonly>True</CodeContractsSuggestReadonly>
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
<CodeContractsEmitXMLDocs>False</CodeContractsEmitXMLDocs>
<CodeContractsCustomRewriterAssembly />
<CodeContractsCustomRewriterClass />
<CodeContractsLibPaths />
<CodeContractsExtraRewriteOptions />
<CodeContractsExtraAnalysisOptions />
<CodeContractsSQLServerOption />
<CodeContractsBaseLineFile />
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
<CodeContractsSkipAnalysisIfCannotConnectToCache>False</CodeContractsSkipAnalysisIfCannotConnectToCache>
<CodeContractsFailBuildOnWarnings>False</CodeContractsFailBuildOnWarnings>
<CodeContractsBeingOptimisticOnExternal>True</CodeContractsBeingOptimisticOnExternal>
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
<CodeContractsReferenceAssembly>DoNotBuild</CodeContractsReferenceAssembly>
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release40|AnyCPU'">
<OutputPath>bin\Release40\</OutputPath>
<DefineConstants>TRACE;NET40</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release40\EncryptedKey.XML</DocumentationFile>
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
<CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
<CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>
<CodeContractsNonNullObligations>True</CodeContractsNonNullObligations>
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
<CodeContractsEnumObligations>True</CodeContractsEnumObligations>
<CodeContractsRedundantAssumptions>True</CodeContractsRedundantAssumptions>
<CodeContractsAssertsToContractsCheckBox>True</CodeContractsAssertsToContractsCheckBox>
<CodeContractsRedundantTests>True</CodeContractsRedundantTests>
<CodeContractsMissingPublicRequiresAsWarnings>True</CodeContractsMissingPublicRequiresAsWarnings>
<CodeContractsMissingPublicEnsuresAsWarnings>False</CodeContractsMissingPublicEnsuresAsWarnings>
<CodeContractsInferRequires>True</CodeContractsInferRequires>
<CodeContractsInferEnsures>False</CodeContractsInferEnsures>
<CodeContractsInferEnsuresAutoProperties>True</CodeContractsInferEnsuresAutoProperties>
<CodeContractsInferObjectInvariants>False</CodeContractsInferObjectInvariants>
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
<CodeContractsSuggestAssumptionsForCallees>False</CodeContractsSuggestAssumptionsForCallees>
<CodeContractsSuggestRequires>False</CodeContractsSuggestRequires>
<CodeContractsNecessaryEnsures>True</CodeContractsNecessaryEnsures>
<CodeContractsSuggestObjectInvariants>False</CodeContractsSuggestObjectInvariants>
<CodeContractsSuggestReadonly>True</CodeContractsSuggestReadonly>
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
<CodeContractsEmitXMLDocs>False</CodeContractsEmitXMLDocs>
<CodeContractsCustomRewriterAssembly />
<CodeContractsCustomRewriterClass />
<CodeContractsLibPaths />
<CodeContractsExtraRewriteOptions />
<CodeContractsExtraAnalysisOptions />
<CodeContractsSQLServerOption />
<CodeContractsBaseLineFile />
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
<CodeContractsSkipAnalysisIfCannotConnectToCache>False</CodeContractsSkipAnalysisIfCannotConnectToCache>
<CodeContractsFailBuildOnWarnings>False</CodeContractsFailBuildOnWarnings>
<CodeContractsBeingOptimisticOnExternal>True</CodeContractsBeingOptimisticOnExternal>
<CodeContractsRuntimeCheckingLevel>ReleaseRequires</CodeContractsRuntimeCheckingLevel>
<CodeContractsReferenceAssembly>DoNotBuild</CodeContractsReferenceAssembly>
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugUnitTest40|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\DebugUnitTest40\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET40;TEST</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>..\..\..\..\..\Common Items\vmAllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\DebugUnitTest40\EncryptedKey.XML</DocumentationFile>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking>
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
<CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
<CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis>
<CodeContractsNonNullObligations>True</CodeContractsNonNullObligations>
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
<CodeContractsEnumObligations>True</CodeContractsEnumObligations>
<CodeContractsRedundantAssumptions>True</CodeContractsRedundantAssumptions>
<CodeContractsAssertsToContractsCheckBox>True</CodeContractsAssertsToContractsCheckBox>
<CodeContractsRedundantTests>True</CodeContractsRedundantTests>
<CodeContractsMissingPublicRequiresAsWarnings>True</CodeContractsMissingPublicRequiresAsWarnings>
<CodeContractsMissingPublicEnsuresAsWarnings>True</CodeContractsMissingPublicEnsuresAsWarnings>
<CodeContractsInferRequires>True</CodeContractsInferRequires>
<CodeContractsInferEnsures>True</CodeContractsInferEnsures>
<CodeContractsInferEnsuresAutoProperties>True</CodeContractsInferEnsuresAutoProperties>
<CodeContractsInferObjectInvariants>True</CodeContractsInferObjectInvariants>
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
<CodeContractsSuggestAssumptionsForCallees>False</CodeContractsSuggestAssumptionsForCallees>
<CodeContractsSuggestRequires>True</CodeContractsSuggestRequires>
<CodeContractsNecessaryEnsures>True</CodeContractsNecessaryEnsures>
<CodeContractsSuggestObjectInvariants>True</CodeContractsSuggestObjectInvariants>
<CodeContractsSuggestReadonly>True</CodeContractsSuggestReadonly>
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
<CodeContractsEmitXMLDocs>False</CodeContractsEmitXMLDocs>
<CodeContractsCustomRewriterAssembly />
<CodeContractsCustomRewriterClass />
<CodeContractsLibPaths />
<CodeContractsExtraRewriteOptions />
<CodeContractsExtraAnalysisOptions />
<CodeContractsSQLServerOption />
<CodeContractsBaseLineFile />
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
<CodeContractsSkipAnalysisIfCannotConnectToCache>False</CodeContractsSkipAnalysisIfCannotConnectToCache>
<CodeContractsFailBuildOnWarnings>False</CodeContractsFailBuildOnWarnings>
<CodeContractsBeingOptimisticOnExternal>True</CodeContractsBeingOptimisticOnExternal>
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
<CodeContractsReferenceAssembly>DoNotBuild</CodeContractsReferenceAssembly>
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugUnitTest|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\DebugUnitTest\</OutputPath>
<DefineConstants>CODE_ANALYSIS;TRACE;DEBUG;NET45;TEST</DefineConstants>
<DefineConstants>TRACE;DEBUG;CODE_ANALYSIS;CODE_ANALYSIS;TEST</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<RunCodeAnalysis>true</RunCodeAnalysis>
Expand Down Expand Up @@ -358,6 +197,7 @@
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
<CodeContractsReferenceAssembly>DoNotBuild</CodeContractsReferenceAssembly>
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
2 changes: 0 additions & 2 deletions Aspects/Security/Cryptography/Ciphers/Hasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespace vm.Aspects.Security.Cryptography.Ciphers
/// <para>
/// Crypto package contents:
/// <list type="number">
/// <item><description>If the salt length is greater than 0, the length of the salt (serialized Int32) - 4 bytes.</description></item>
/// <item><description>If the salt length is greater than 0, the bytes of the salt.</description></item>
/// <item><description>Length of the hash (serialized Int32) - 4 bytes.</description></item>
/// <item><description>The bytes of the hash.</description></item>
/// </list>
/// </para>
Expand Down
7 changes: 3 additions & 4 deletions Aspects/Security/Cryptography/Ciphers/KeyedHasher .cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace vm.Aspects.Security.Cryptography.Ciphers
/// <para>
/// Crypto package contents:
/// <list type="number">
/// <item><description>Length of the hash (serialized Int32) - 4 bytes.</description></item>
/// <item><description>The bytes of the hash.</description></item>
/// </list>
/// </para>
Expand Down Expand Up @@ -440,7 +439,7 @@ void InitializeAsymmetricKeys(

bool IsHashKeyInitialized
{
get { return _hashKey.Length > 0; }
get { return _hashKey?.Length > 0; }
}

/// <summary>
Expand Down Expand Up @@ -531,7 +530,7 @@ void DecryptHashKey(
/// </summary>
/// <returns>CryptoStream.</returns>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "It will be disposed by the calling code.")]
static CryptoStream CreateHashStream(
protected virtual CryptoStream CreateHashStream(
HashAlgorithm hashAlgorithm)
{
Contract.Requires<ArgumentNullException>(hashAlgorithm != null, "hashAlgorithm");
Expand All @@ -549,7 +548,7 @@ static CryptoStream CreateHashStream(
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "1")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "2", Justification = "salt is conditionally validated.")]
static byte[] FinalizeHashing(
protected virtual byte[] FinalizeHashing(
CryptoStream hashStream,
HashAlgorithm hashAlgorithm)
{
Expand Down
6 changes: 6 additions & 0 deletions Aspects/Security/Cryptography/Ciphers/MacKey/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
Loading

0 comments on commit 910dd6f

Please sign in to comment.