Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > A simpler trunc...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 8818 of 9110
Post > Topic >>

A simpler truncation function that renders credit card numbers

by "Serman D." <serman_d@[EMAIL PROTECTED] > Apr 23, 2008 at 01:21 AM

Background: The Payment Card Industry (PCI) Data Security Standard
(PCI DSS) is a standard for financial institutions. It requires
sensitive information, such as credit card numbers, to be "unreadable
anywhere it is stored" using ha****ng, truncation or encryption.

I am looking for a simple truncation function that replaces the last
four digits in the given numeric with four characters (e.g. '*').  As
as Perl programmer (where a simple "s/.{4}$/****/" would suffice), the
resulting SQL/PL code strikes me as unnecessarily complex.  Is there a
simpler way?

-- Replace last four characters in decimal number with stars.
-- E.g. 1234567890123456 -> 123456789012****               .
CREATE FUNCTION FUNC_MASK_LAST_4 (cardno decimal(21,0))
  RETURNS CHAR(32)
  NO EXTERNAL ACTION
  DETERMINISTIC
RETURN SUBSTR(STRIP(CAST(cardno AS CHAR(32)), T, ' '),
                    32 - LENGTH(STRIP(CAST(cardno as char(32)), l,
'0')) + 1,
                    CAST(CEIL(LOG10(cardno)) AS INT) - 4) || '****'
@[EMAIL PROTECTED]
 table largenum (lval decimal(21,0) not null)
@[EMAIL PROTECTED]
 into largenum values
(1234567890123456789),
( 123456789012345678),
(  12345678901234567),
(   1234567890123456),
(    123456789012345),
(     12345678901234),
(      1234567890123),
(       123456789012),
(        12345678901),
(         1234567890),
(          123456789),
(           12345678),
(            1234567),
(             123456),
(              12345),
(               1234)
@[EMAIL PROTECTED]
 lval, FUNC_MASK_LAST_4(lval) as masked from largenum
@[EMAIL PROTECTED]
                    MASKED
----------------------- --------------------------------
   1234567890123456789. 123456789012345****
    123456789012345678. 12345678901234****
     12345678901234567. 1234567890123****
      1234567890123456. 123456789012****
       123456789012345. 12345678901****
        12345678901234. 1234567890****
         1234567890123. 123456789****
          123456789012. 12345678****
           12345678901. 1234567****
            1234567890. 123456****
             123456789. 12345****
              12345678. 1234****
               1234567. 123****
                123456. 12****
                 12345. 1****
                  1234. ****

  16 record(s) selected.


https://www.pcisecuritystandards.org/pdfs/pci_dss_v1-1.pdf

Regards,
Serman D.
--
 




 2 Posts in Topic:
A simpler truncation function that renders credit card numbers
"Serman D." <  2008-04-23 01:21:46 
Re: A simpler truncation function that renders credit card numbe
Serge Rielau <srielau@  2008-04-23 08:21:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 20 0:21:03 CDT 2008.