Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Function to Redact SSNs and CCs from a string 1

Status
Not open for further replies.

annethorne

Programmer
Apr 13, 2005
28
US
Hi everyone,

I need a function to redact possible SSNs and CCs from a string.

This is for an application that receives messages from customers, which may contain SSNs or CCs. Instead of passing on that message, we want to redact it of the sensitive information.

We do have some SQL functions that do this, but I want to duplicate what they do in C# as we don't want to use Databases:



Have any of you done this sort of thing before?
All the Best to You!
Anne
 
I think I have found my answer:

[pre]private static string RedactCC(string stringToRedact)
{
const string pattern = @"(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})";
stringToRedact = Regex.Replace(
stringToRedact,
pattern,
m => "***-**-" + m.Value.Substring(m.Value.Length - 4, 4));
return stringToRedact;
}[/pre]

[pre]private static string RedactSSN(string stringToRedact)
{
const string pattern = @"\d{3}-\d{2}-\d{4}";
stringToRedact = Regex.Replace(
stringToRedact,
pattern,
m => "***-**-" + m.Value.Substring(m.Value.Length - 4, 4));
return stringToRedact;
}[/pre]

Maybe this post will help someone else in the future.
:) Anne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top