Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need Function to Redact SSNs and CCs from a string

Need Function to Redact SSNs and CCs from a string

Scheduled Pinned Locked Moved C#
csharpdatabasequestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AnneThorne
    wrote on last edited by
    #1

    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

    Z 1 Reply Last reply
    0
    • A AnneThorne

      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

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • Z ZurdoDev

        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.

        A Offline
        A Offline
        AnneThorne
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • A AnneThorne

          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

          A Offline
          A Offline
          AnneThorne
          wrote on last edited by
          #4

          I have found this reference : http://foobook.org/erbere/scraps/find-and-replace-text-with-regex/[^] :)

          A 1 Reply Last reply
          0
          • A AnneThorne

            I have found this reference : http://foobook.org/erbere/scraps/find-and-replace-text-with-regex/[^] :)

            A Offline
            A Offline
            AnneThorne
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups