-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from dlmelendez/rel/v1.0
Rel/v1.0 prepare for 1.0 release
- Loading branch information
Showing
6 changed files
with
323 additions
and
187 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/ElCamino.AspNetCore.Identity.DocumentDB/Helpers/HashHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// MIT License Copyright 2017 (c) David Melendez. All rights reserved. See License.txt in the project root for license information. | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace ElCamino.AspNetCore.Identity.DocumentDB.Helpers | ||
{ | ||
public static class HashHelper | ||
{ | ||
public static SHA256 sha = SHA256.Create(); | ||
|
||
public static string ConvertToHash(string input) | ||
{ | ||
return GetHash(sha, input); | ||
} | ||
|
||
private static string GetHash(SHA256 shaHash, string input) | ||
{ | ||
// Convert the input string to a byte array and compute the hash. | ||
byte[] data = shaHash.ComputeHash(Encoding.UTF8.GetBytes(input)); | ||
Console.WriteLine(string.Format("Key Size before hash: {0} bytes", Encoding.UTF8.GetBytes(input).Length)); | ||
|
||
// Create a new Stringbuilder to collect the bytes | ||
// and create a string. | ||
StringBuilder sBuilder = new StringBuilder(32); | ||
|
||
// Loop through each byte of the hashed data | ||
// and format each one as a hexadecimal string. | ||
for (int i = 0; i < data.Length; i++) | ||
{ | ||
sBuilder.Append(data[i].ToString("X2")); | ||
} | ||
Console.WriteLine(string.Format("Key Size after hash: {0} bytes", data.Length)); | ||
|
||
// Return the hexadecimal string. | ||
return sBuilder.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.