Need Function to Redact SSNs and CCs from a string
-
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
-
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
-
This sounds like a good case for RegEx. What method were you using in SQL?
There are only 10 types of people in the world, those who understand binary and those who don't.
The functions are here: http://files.engineering.com/getfile.aspx?folder=0cc581bd-5691-4c60-b0b2-c35b2b7f7a10&file=dbo.fnFixCCandSSN-sqlFunction.txt http://files.engineering.com/getfile.aspx?folder=b19b9e78-975a-4ca2-9fec-aa852367819b&file=dbo.fnIsLuhnValid-sqlFunction.txt Thank you so very much for your help!!! :) Anne
-
The functions are here: http://files.engineering.com/getfile.aspx?folder=0cc581bd-5691-4c60-b0b2-c35b2b7f7a10&file=dbo.fnFixCCandSSN-sqlFunction.txt http://files.engineering.com/getfile.aspx?folder=b19b9e78-975a-4ca2-9fec-aa852367819b&file=dbo.fnIsLuhnValid-sqlFunction.txt Thank you so very much for your help!!! :) Anne
I have found this reference : http://foobook.org/erbere/scraps/find-and-replace-text-with-regex/[^] :)
-
I have found this reference : http://foobook.org/erbere/scraps/find-and-replace-text-with-regex/[^] :)
I think I have found my answer:
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;
}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;
}Maybe this post will help someone else in the future. :) Anne