incorporate MBS.Security.Cryptography extensions into MBS.Framework since it doesn't necessitate a separate library
This commit is contained in:
parent
f5c2801e70
commit
45c2cd9979
@ -11,6 +11,7 @@
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\MichaelBecker.snk</AssemblyOriginatorKeyFile>
|
||||
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -48,6 +49,7 @@
|
||||
<Compile Include="Drawing\Vector.cs" />
|
||||
<Compile Include="ArrayExtensions.cs" />
|
||||
<Compile Include="Reflection.cs" />
|
||||
<Compile Include="Security\Cryptography\ExtensionMethods.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
||||
27
MBS.Framework/Security/Cryptography/ExtensionMethods.cs
Normal file
27
MBS.Framework/Security/Cryptography/ExtensionMethods.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user