Obfuscating credit card or Social Security numbers


Here’s a function that will obfuscate a string of credit card or social security numbers. It can be useful to prevent information from being displayed in reports or other output from the database.


You can download the script from the file attachment.

Create_fn_ReplaceNumberSequence_BlogPost.sql

Comments (3)

  1. Duncan says:

    Obfuscating in databases can be a bit more tricky if you want to keep the index distribution the same (if you can) for the purpose of performance testing.  However a straight replacement cypher is not secure enough….

  2. tommills says:

    To clarify the purpose of this function…

    It was originally written to obfuscate credit card numbers that might be present in a report. Specifically a blocked process report where the parameters contained credit card numbers.

    This function is not meant to encrypt credit card numbers. It’s use is intended to be for output from the database.

  3. tommills says:

    Thanks for the feedback. The options for the re-org code was added at the last minute. It should work fine now.