This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #1 from healexsystems/feature/add-PID-hashing
Add hashing capability for IDs
- Loading branch information
Showing
7 changed files
with
116 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Healex.HL7v2Anonymizer.Services; | ||
|
||
|
||
namespace Healex.HL7v2Anonymizer.Tests | ||
{ | ||
[TestClass] | ||
public class HashGeneratorTests | ||
{ | ||
[TestMethod] | ||
public void TestGetStringHash() | ||
{ | ||
var testPid = "48234029834029834"; | ||
var hashedtestPid = HashGenerator.HashString(testPid); | ||
|
||
Assert.IsNotNull(hashedtestPid); | ||
Assert.AreEqual(hashedtestPid, "750678352"); | ||
} | ||
} | ||
} |
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
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,19 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace Healex.HL7v2Anonymizer.Services | ||
{ | ||
public class HashGenerator | ||
{ | ||
public static string HashString(string value) | ||
{ | ||
var hasher = SHA512.Create(); | ||
var hashedValue = hasher.ComputeHash(Encoding.UTF8.GetBytes(value)); | ||
|
||
var hashAsInt = BitConverter.ToInt32(hashedValue, 0); | ||
var positiveHashedValue = Math.Abs(hashAsInt); | ||
return positiveHashedValue.ToString(); | ||
} | ||
} | ||
} |
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