incorporate MBS.Security.Cryptography extensions into MBS.Framework since it doesn't necessitate a separate library

This commit is contained in:
Michael Becker 2020-01-06 00:21:25 -05:00
parent f5c2801e70
commit 45c2cd9979
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
2 changed files with 29 additions and 0 deletions

View File

@ -11,6 +11,7 @@
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<SignAssembly>true</SignAssembly> <SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\MichaelBecker.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\..\MichaelBecker.snk</AssemblyOriginatorKeyFile>
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -48,6 +49,7 @@
<Compile Include="Drawing\Vector.cs" /> <Compile Include="Drawing\Vector.cs" />
<Compile Include="ArrayExtensions.cs" /> <Compile Include="ArrayExtensions.cs" />
<Compile Include="Reflection.cs" /> <Compile Include="Reflection.cs" />
<Compile Include="Security\Cryptography\ExtensionMethods.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -0,0 +1,27 @@
using System.Security.Cryptography;
namespace MBS.Framework.Security.Cryptography
{
public static class ExtensionMethods
{
/// <summary>
/// Computes the hash of the specified value in the given encoding.
/// </summary>
/// <returns>The hash.</returns>
/// <param name="value">Value.</param>
public static string ComputeHash(this HashAlgorithm ha, string value, System.Text.Encoding encoding = null)
{
if (encoding == null) encoding = System.Text.Encoding.UTF8;
byte[] buffer = encoding.GetBytes(value);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
byte[] output = ha.ComputeHash(buffer);
for (int i = 0; i < output.Length; i++)
{
sb.Append(output[i].ToString("x").PadLeft(2, '0'));
}
return sb.ToString();
}
}
}