Re: [PHP-DB] Credit Card Encryption
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 What I wrote there will work but I would highly recommend recompiling PHP with the --with-mcrypt --with-mhash switches. The mcrypt libraries can be found on sourceforge. http://libmcrypt.sourceforge.net Jason Gerfen wrote: > I got messaged off list which I don't appreciate. > > But, yes PHP5 only or you could replace the lines for PHP4 and on: > > $keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); > > With: > > if( !function_exists( mhash ) ) { > $keys[] = sha1( sha1( $array[$x] ) ); > } elseif( !function_exists( sha1 ) ) { > $keys[] = md5( md5( $array[$x] ) ); > } else { > $keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); > } > > That will look to see if the 'mhash()', 'sha1()' functions exist and use > them accordingly. HTH. > > Jason Gerfen wrote: >> Jason Gerfen wrote: >>> Daniel Brown wrote: On Dec 19, 2007 2:41 AM, Keith Spiller <[EMAIL PROTECTED]> wrote: > Ok I've done some research and some thinking. What about storing orders > in > the database (product info and customer info) and then using GnuPG or PGP > to > send the credit card info to the merchant? This way the credit card > information is not stored on the server or in the database but only in > printed format by the merchant. Since my client processes all of the > credit > card orders by hand this seems like an ideal solution. I had a client that did offline (manual) processing of credit card orders as well. With liability issues and the problems that others have already pointed out, storing the credit card information was not an option, yet my client still needed some way of having the data available offline. Consider the following: ISSUERLENGTH Diner's Club/Carte Blanche 14 American Express 15 VISA 13 or 16 MasterCard16 Discover 16 Security checks aside (like making sure they selected the type of card and that it matched the algorithm - VISA beginning with 4 and being strlen($_POST['cardnum']) == 13 or 16, MasterCard being 16, beginning with 51xx to 55xx, et cetera), I then had a hybrid of storage and delivery. Mail the first digits to the sales email address(es) on file. Three addresses on two domains were used for redundancy in this case. Store the remaining digits in the database. You could write your own encryption algorithm or use one that is publicly-available and reversible (Blowfish is what I was using, at 128, key length of 56 lower ASCII characters, padded with 7 on the key and four on the output - MD5, SHA1, et al are NOT options here). The sales department then received the first digits of the credit card number via email, which stated it was an order key. Again, in my >>> Using the order number as the key is bad practice. Here is a random key >>> generator that you could use for your public/private keys and still use >>> the blowfish cipher as your method of encrypting: >>> >> function ReadFolder( $folder ) >>> { >>> if( ( empty( $folder ) ) || ( !is_dir( $folder ) ) ) { >>> $rand_image = GenerateError( "Couldn't open directory" ); >>> } else { >>> $rand_image = array(); >>> if( $handle = opendir( $folder ) ) { >>>while( false !== ( $file = readdir( $handle ) ) ) { >>> if( $file != "." && $file != ".." && $file != "index.html" && >>> !is_dir( $file ) ) { >>> $rand_image[] = $file; >>> } >>>} >>>closedir( $handle ); >>> } >>> } >>> return $rand_image; >>> } >>> function MakeSuperRandom() >>> { >>> return srand( ( double ) microtime( time() ) * 10 ); >>> } >>> function PickRandomImages( $array ) >>> { >>> $num1 = count( $array ); >>> $num1 = $num1 - 1; >>> MakeSuperRandom(); >>> $img_num = rand( 3, $num1 ); >>> $image[] = $array[$img_num]; >>> $num2 = count( $array ); >>> $num2 = $num2 - 1; >>> MakeSuperRandom(); >>> $img_num = rand( 3, $num2 ); >>> $image[] = $array[$img_num]; >>> $num3 = count( $array ); >>> $num3 = $num3 - 1; >>> MakeSuperRandom(); >>> $img_num = rand( 3, $num3 ); >>> $image[] = $array[$img_num]; >>> return $image; >>> } >>> function ChkArray( $array ) >>> { >>> if( ( empty( $array ) ) || ( count( $array ) > 3 ) ) { >>> $data = 1; >>> } else { >>> $data = 0; >>> } >>> return $data; >>> } >>> function GeneratePrivKey( $array ) >>> { >>> if( empty( $array ) ) { >>> $data = GenerateError( "Missing data for GeneratePrivKey function." ); >>> } else { >>> for( $x = 0; $x < count( $array ); $x++ ) { >>>$keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); >>> } >>> for( $y = 0; $y < count( $keys ); $y++ ) { >>>if( count( $keys ) == $keys[$y] ) { >>> $data .= $keys[$y]; >>>} else { >>> $data .= $keys[
Re: [PHP-DB] Credit Card Encryption
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I got messaged off list which I don't appreciate. But, yes PHP5 only or you could replace the lines for PHP4 and on: $keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); With: if( !function_exists( mhash ) ) { $keys[] = sha1( sha1( $array[$x] ) ); } elseif( !function_exists( sha1 ) ) { $keys[] = md5( md5( $array[$x] ) ); } else { $keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); } That will look to see if the 'mhash()', 'sha1()' functions exist and use them accordingly. HTH. Jason Gerfen wrote: > Jason Gerfen wrote: >> Daniel Brown wrote: >>> On Dec 19, 2007 2:41 AM, Keith Spiller <[EMAIL PROTECTED]> wrote: Ok I've done some research and some thinking. What about storing orders in the database (product info and customer info) and then using GnuPG or PGP to send the credit card info to the merchant? This way the credit card information is not stored on the server or in the database but only in printed format by the merchant. Since my client processes all of the credit card orders by hand this seems like an ideal solution. >>> I had a client that did offline (manual) processing of credit card >>> orders as well. With liability issues and the problems that others >>> have already pointed out, storing the credit card information was not >>> an option, yet my client still needed some way of having the data >>> available offline. >>> Consider the following: >>> ISSUERLENGTH >>> Diner's Club/Carte Blanche 14 >>> American Express 15 >>> VISA 13 or 16 >>> MasterCard16 >>> Discover 16 >>> Security checks aside (like making sure they selected the type of >>> card and that it matched the algorithm - VISA beginning with 4 and >>> being strlen($_POST['cardnum']) == 13 or 16, MasterCard being 16, >>> beginning with 51xx to 55xx, et cetera), I then had a hybrid of >>> storage and delivery. >>> Mail the first digits to the sales email >>> address(es) on file. Three addresses on two domains were used for >>> redundancy in this case. Store the remaining digits in the database. >>> You could write your own encryption algorithm or use one that is >>> publicly-available and reversible (Blowfish is what I was using, at >>> 128, key length of 56 lower ASCII characters, padded with 7 on the key >>> and four on the output - MD5, SHA1, et al are NOT options here). >>> The sales department then received the first digits of the credit >>> card number via email, which stated it was an order key. Again, in my >> Using the order number as the key is bad practice. Here is a random key >> generator that you could use for your public/private keys and still use >> the blowfish cipher as your method of encrypting: > >> > function ReadFolder( $folder ) >> { >> if( ( empty( $folder ) ) || ( !is_dir( $folder ) ) ) { >> $rand_image = GenerateError( "Couldn't open directory" ); >> } else { >> $rand_image = array(); >> if( $handle = opendir( $folder ) ) { >>while( false !== ( $file = readdir( $handle ) ) ) { >> if( $file != "." && $file != ".." && $file != "index.html" && >> !is_dir( $file ) ) { >> $rand_image[] = $file; >> } >>} >>closedir( $handle ); >> } >> } >> return $rand_image; >> } > >> function MakeSuperRandom() >> { >> return srand( ( double ) microtime( time() ) * 10 ); >> } > >> function PickRandomImages( $array ) >> { >> $num1 = count( $array ); >> $num1 = $num1 - 1; >> MakeSuperRandom(); > >> $img_num = rand( 3, $num1 ); >> $image[] = $array[$img_num]; > >> $num2 = count( $array ); >> $num2 = $num2 - 1; >> MakeSuperRandom(); > >> $img_num = rand( 3, $num2 ); >> $image[] = $array[$img_num]; > >> $num3 = count( $array ); >> $num3 = $num3 - 1; >> MakeSuperRandom(); > >> $img_num = rand( 3, $num3 ); >> $image[] = $array[$img_num]; >> return $image; >> } > >> function ChkArray( $array ) >> { >> if( ( empty( $array ) ) || ( count( $array ) > 3 ) ) { >> $data = 1; >> } else { >> $data = 0; >> } >> return $data; >> } > >> function GeneratePrivKey( $array ) >> { >> if( empty( $array ) ) { >> $data = GenerateError( "Missing data for GeneratePrivKey function." ); >> } else { >> for( $x = 0; $x < count( $array ); $x++ ) { >>$keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); >> } >> for( $y = 0; $y < count( $keys ); $y++ ) { >>if( count( $keys ) == $keys[$y] ) { >> $data .= $keys[$y]; >>} else { >> $data .= $keys[$y] . ":"; >>} >> } >> } >> return $data; >> } > >> function GeneratePubKey( $data ) >> { >> return md5( $data ); >> } > >> function EncData( $data, $key ) >> { >> $td = mcrypt_module_open( 'rijndael-256', '', 'ofb', '' ); >> $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_DEV_RANDOM ); >> $ks = mcrypt_enc_get_key_s
Re: [PHP-DB] Credit Card Encryption
On Dec 19, 2007 11:59 PM, Bastien Koert <[EMAIL PROTECTED]> wrote: > I take the view that I warn our customers about the dangers, and if really > concerning ask for an indemnity or a very formal request for change. I really > try to convince them of the correct path and keep any emails regarding the > issues as backup I was going to say the same thing. If PCI is really becoming that big of an issue where there's even the slightest threat of backlash to the developer, an indemnification clause (Santa's European cousin) should probably be the course of action. That said, I think I'm going to peruse the compliance information at that link you sent earlier. -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Credit Card Encryption
Gary, I take the view that I warn our customers about the dangers, and if really concerning ask for an indemnity or a very formal request for change. I really try to convince them of the correct path and keep any emails regarding the issues as backup Its a drag when you really have to consider how to cover your ass on this. Lawyers suck too. ;-P bastien> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: php-db@lists.php.net> Subject: RE: [PHP-DB] Credit Card Encryption> Date: Wed, 19 Dec 2007 23:21:52 -0500> > Hmm,> > This is kind of throwing a new twist on things.> > When it comes to liability, who is liable, the merchant running the system, the develper that created the system, or both?> > If the develper is included, would that be mitigated in that he created the system to the merchant's specifications?> > Also, in terms of the developer, would this be covered under errors and omissions insurance, or would they take the position that> the developer should have known better and was negligent in creating a non-compliant system leaving the developer on the hook for> damages?> > Gary> > > -Original Message-> > From: Bastien Koert [mailto:[EMAIL PROTECTED]> > Sent: Wed, December 19, 2007 11:02 PM> > To: Daniel Brown> > Cc: Keith Spiller; php-db@lists.php.net> > Subject: RE: [PHP-DB] Credit Card Encryption> >> >> >> > Dan,> >> > Normally I would completely agree, its our job to find those> > solutions. Unfortunately, the sector that my FT job deals> > with is retail and many of our clients are in this bind with> > PCI data. Hefty fines are charged to those not in compliance.> > The major CC companies are taking this so seriously and the> > ramifications are being felt in many IT shops. Compliance> > failure can lead to loss o privileges to accept CCs.> >> > Its gonna force us to be more creative in how we handle the> > data and create the applications that allow our clients to> > offer ecommerce, we will have to learn some business skills> > to make this happen. It may mean that its becomes more> > contractual in dealing with third parties, where the ecommece> > shop effects payment on behalf of the vendors. The OP may> > need to help his client work out a better way to manage the> > transactions between the related parties by finding ways to> > automate the various transactions and provide gateway access...> >> > I, too, like to eat... ;-P> >> > bastien> >> >> > > Date: Wed, 19 Dec 2007 17:21:57 -0500> From:> > [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: Re:> > [PHP-DB] Credit Card Encryption> CC: [EMAIL PROTECTED];> > php-db@lists.php.net> > On Dec 19, 2007 4:45 PM, Bastien> > Koert <[EMAIL PROTECTED]> wrote:> >> > Nope, I still> > would not recommmend it. The only place the CC data should> > travel to is the payment gateway. Anything else is a security> > risk. Why does your client process by hand? They should be> > using a payment gateway.> > That's true, Bastien, but if for> > whatever reason it's not an> option for them, what? Tell them> > it's tough cookies and they're SOL?> > Our job as programmers> > - especially freelance - is to make things> happen as safely> > and securely as we can, but as a bottom line, make it>> > happen. I'm sure we (most of us) take the responsibility to>> > discourage a client from making such choices, and to educate> > them on> alternatives that are better for their interests,> > but still - at the> end of the day, we're still just code> > monkeys. We're expected to> build what the client needs, or> > else they'll find someone else to do> it for them.> > And I> > don't really like to go hungry. ;-)> > -- > Daniel P. Brown>> > [Phone Numbers Go Here!]> [They're Hidden From View!]> > If> > at first you don't succeed, stick to what you know best so> > that you> can make enough money to pay someone else to do it for you.> > _> > Exercise your brain! Try Flexicon!> > http://puzzles.sympatico.msn.ca/chicktionary/index.html?icid=htmlsig> _ Exercise your brain! Try Flexicon! http://puzzles.sympatico.msn.ca/chicktionary/index.html?icid=htmlsig
RE: [PHP-DB] Credit Card Encryption
Hmm, This is kind of throwing a new twist on things. When it comes to liability, who is liable, the merchant running the system, the develper that created the system, or both? If the develper is included, would that be mitigated in that he created the system to the merchant's specifications? Also, in terms of the developer, would this be covered under errors and omissions insurance, or would they take the position that the developer should have known better and was negligent in creating a non-compliant system leaving the developer on the hook for damages? Gary > -Original Message- > From: Bastien Koert [mailto:[EMAIL PROTECTED] > Sent: Wed, December 19, 2007 11:02 PM > To: Daniel Brown > Cc: Keith Spiller; php-db@lists.php.net > Subject: RE: [PHP-DB] Credit Card Encryption > > > > Dan, > > Normally I would completely agree, its our job to find those > solutions. Unfortunately, the sector that my FT job deals > with is retail and many of our clients are in this bind with > PCI data. Hefty fines are charged to those not in compliance. > The major CC companies are taking this so seriously and the > ramifications are being felt in many IT shops. Compliance > failure can lead to loss o privileges to accept CCs. > > Its gonna force us to be more creative in how we handle the > data and create the applications that allow our clients to > offer ecommerce, we will have to learn some business skills > to make this happen. It may mean that its becomes more > contractual in dealing with third parties, where the ecommece > shop effects payment on behalf of the vendors. The OP may > need to help his client work out a better way to manage the > transactions between the related parties by finding ways to > automate the various transactions and provide gateway access... > > I, too, like to eat... ;-P > > bastien > > > > Date: Wed, 19 Dec 2007 17:21:57 -0500> From: > [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: Re: > [PHP-DB] Credit Card Encryption> CC: [EMAIL PROTECTED]; > php-db@lists.php.net> > On Dec 19, 2007 4:45 PM, Bastien > Koert <[EMAIL PROTECTED]> wrote:> >> > Nope, I still > would not recommmend it. The only place the CC data should > travel to is the payment gateway. Anything else is a security > risk. Why does your client process by hand? They should be > using a payment gateway.> > That's true, Bastien, but if for > whatever reason it's not an> option for them, what? Tell them > it's tough cookies and they're SOL?> > Our job as programmers > - especially freelance - is to make things> happen as safely > and securely as we can, but as a bottom line, make it> > happen. I'm sure we (most of us) take the responsibility to> > discourage a client from making such choices, and to educate > them on> alternatives that are better for their interests, > but still - at the> end of the day, we're still just code > monkeys. We're expected to> build what the client needs, or > else they'll find someone else to do> it for them.> > And I > don't really like to go hungry. ;-)> > -- > Daniel P. Brown> > [Phone Numbers Go Here!]> [They're Hidden From View!]> > If > at first you don't succeed, stick to what you know best so > that you> can make enough money to pay someone else to do it for you. > _ > Exercise your brain! Try Flexicon! > http://puzzles.sympatico.msn.ca/chicktionary/index.html?icid=htmlsig -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Credit Card Encryption
Dan, Normally I would completely agree, its our job to find those solutions. Unfortunately, the sector that my FT job deals with is retail and many of our clients are in this bind with PCI data. Hefty fines are charged to those not in compliance. The major CC companies are taking this so seriously and the ramifications are being felt in many IT shops. Compliance failure can lead to loss o privileges to accept CCs. Its gonna force us to be more creative in how we handle the data and create the applications that allow our clients to offer ecommerce, we will have to learn some business skills to make this happen. It may mean that its becomes more contractual in dealing with third parties, where the ecommece shop effects payment on behalf of the vendors. The OP may need to help his client work out a better way to manage the transactions between the related parties by finding ways to automate the various transactions and provide gateway access... I, too, like to eat... ;-P bastien > Date: Wed, 19 Dec 2007 17:21:57 -0500> From: [EMAIL PROTECTED]> To: [EMAIL > PROTECTED]> Subject: Re: [PHP-DB] Credit Card Encryption> CC: [EMAIL > PROTECTED]; php-db@lists.php.net> > On Dec 19, 2007 4:45 PM, Bastien Koert > <[EMAIL PROTECTED]> wrote:> >> > Nope, I still would not recommmend it. The > only place the CC data should travel to is the payment gateway. Anything else > is a security risk. Why does your client process by hand? They should be > using a payment gateway.> > That's true, Bastien, but if for whatever reason > it's not an> option for them, what? Tell them it's tough cookies and they're > SOL?> > Our job as programmers - especially freelance - is to make things> > happen as safely and securely as we can, but as a bottom line, make it> > happen. I'm sure we (most of us) take the responsibility to> discourage a > client from making such choices, and to educate them on> alternatives that > are better for their interests, but still - at the> end of the day, we're > still just code monkeys. We're expected to> build what the client needs, or > else they'll find someone else to do> it for them.> > And I don't really like > to go hungry. ;-)> > -- > Daniel P. Brown> [Phone Numbers Go Here!]> [They're > Hidden From View!]> > If at first you don't succeed, stick to what you know > best so that you> can make enough money to pay someone else to do it for you. _ Exercise your brain! Try Flexicon! http://puzzles.sympatico.msn.ca/chicktionary/index.html?icid=htmlsig
Re: [PHP-DB] Credit Card Encryption
On Dec 19, 2007 4:45 PM, Bastien Koert <[EMAIL PROTECTED]> wrote: > > Nope, I still would not recommmend it. The only place the CC data should > travel to is the payment gateway. Anything else is a security risk. Why does > your client process by hand? They should be using a payment gateway. That's true, Bastien, but if for whatever reason it's not an option for them, what? Tell them it's tough cookies and they're SOL? Our job as programmers - especially freelance - is to make things happen as safely and securely as we can, but as a bottom line, make it happen. I'm sure we (most of us) take the responsibility to discourage a client from making such choices, and to educate them on alternatives that are better for their interests, but still - at the end of the day, we're still just code monkeys. We're expected to build what the client needs, or else they'll find someone else to do it for them. And I don't really like to go hungry. ;-) -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Credit Card Encryption
Nope, I still would not recommmend it. The only place the CC data should travel to is the payment gateway. Anything else is a security risk. Why does your client process by hand? They should be using a payment gateway. bastien> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]; php-db@lists.php.net> Subject: Re: [PHP-DB] Credit Card Encryption> Date: Wed, 19 Dec 2007 00:41:36 -0700> > Ok I've done some research and some thinking. What about storing orders in > the database (product info and customer info) and then using GnuPG or PGP to > send the credit card info to the merchant? This way the credit card > information is not stored on the server or in the database but only in > printed format by the merchant. Since my client processes all of the credit > card orders by hand this seems like an ideal solution.> > What is more, the order and customer info do not need to be present in the > encrypted emails. That way the email does not contain a customer name, but > only an order id (which could even be a unique and hidden value stored via > AES in the mysql db).> > What are your thoughts?> > Keith> > - Original Message - > From: "Bastien Koert" <[EMAIL PROTECTED]>> To: "Keith Spiller" <[EMAIL PROTECTED]>; > Sent: Tuesday, December 18, 2007 9:41 PM> Subject: RE: [PHP-DB] Credit Card Encryption> > > > Think very carefully about what you want to do here. PCI (payment card > industry) has radically changed the rules about how CC data is stored in a > networked environment. If your data environment is shared (shared web > hosting), don't even think about it. There are a large number of rules that > you need to follow to make your data systems PCI compliant [ > http://www.pcicomplianceguide.org/ ] and they are not easy to follow. Things > like strong encryption, code audits by qualified third parties etc.> > If you absolutely need to store the data (many of my large clients do this):> 1. the database server should not be web facing, nor accessible internally > by the web servers> 2. the access (physical and electronic) should be extremely limited> 3. the facility that holds the data should be hardened with limited > controlled access> 4. provide a cross reference number to the CC that other applications can > use to replace the CC number> > If you are storing transactional data, just store the confirmation number > that is returned by the payment gateway that you use. Let the payment > gateway assume the risks of handling the data, its what they get paid for. > If the data is for re-occurring payments, let the payment gateway handle it, > many support these kinds of payments.> > Bastien> > From: [EMAIL PROTECTED]> To: php-db@lists.php.net> CC: > > [EMAIL PROTECTED]> Date: Tue, 18 Dec 2007 18:20:08 -0700> Subject: > > [PHP-DB] Credit Card Encryption> > Hi Everyone,> > I'm trying to determine > > the best method to store credit card numbers in a > mysql database. As yet > > I have been unable to determine whether I should use > MySQL AES, DES or a > > PHP encryption method. I would greatly appreciate any > advice you guys > > could offer.> > Thanks.> > Keith > > -- > PHP Database Mailing List > > (http://www.php.net/)> To unsubscribe, visit: > > http://www.php.net/unsub.php>> _> Discover new ways to stay in touch with Windows Live! Visit the City @ Live > today!> http://getyourliveid.ca/?icid=LIVEIDENCA006 > _ Introducing the City @ Live! Take a tour! http://getyourliveid.ca/?icid=LIVEIDENCA006
Re: [PHP-DB] Credit Card Encryption
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jason Gerfen wrote: > Daniel Brown wrote: >> On Dec 19, 2007 2:41 AM, Keith Spiller <[EMAIL PROTECTED]> wrote: >>> Ok I've done some research and some thinking. What about storing orders in >>> the database (product info and customer info) and then using GnuPG or PGP to >>> send the credit card info to the merchant? This way the credit card >>> information is not stored on the server or in the database but only in >>> printed format by the merchant. Since my client processes all of the credit >>> card orders by hand this seems like an ideal solution. >> I had a client that did offline (manual) processing of credit card >> orders as well. With liability issues and the problems that others >> have already pointed out, storing the credit card information was not >> an option, yet my client still needed some way of having the data >> available offline. > >> Consider the following: > >> ISSUERLENGTH >> Diner's Club/Carte Blanche 14 >> American Express 15 >> VISA 13 or 16 >> MasterCard16 >> Discover 16 > >> Security checks aside (like making sure they selected the type of >> card and that it matched the algorithm - VISA beginning with 4 and >> being strlen($_POST['cardnum']) == 13 or 16, MasterCard being 16, >> beginning with 51xx to 55xx, et cetera), I then had a hybrid of >> storage and delivery. > >> Mail the first digits to the sales email >> address(es) on file. Three addresses on two domains were used for >> redundancy in this case. Store the remaining digits in the database. >> You could write your own encryption algorithm or use one that is >> publicly-available and reversible (Blowfish is what I was using, at >> 128, key length of 56 lower ASCII characters, padded with 7 on the key >> and four on the output - MD5, SHA1, et al are NOT options here). > >> The sales department then received the first digits of the credit >> card number via email, which stated it was an order key. Again, in my > > Using the order number as the key is bad practice. Here is a random key > generator that you could use for your public/private keys and still use > the blowfish cipher as your method of encrypting: > > function ReadFolder( $folder ) > { > if( ( empty( $folder ) ) || ( !is_dir( $folder ) ) ) { > $rand_image = GenerateError( "Couldn't open directory" ); > } else { > $rand_image = array(); > if( $handle = opendir( $folder ) ) { >while( false !== ( $file = readdir( $handle ) ) ) { > if( $file != "." && $file != ".." && $file != "index.html" && > !is_dir( $file ) ) { > $rand_image[] = $file; > } >} >closedir( $handle ); > } > } > return $rand_image; > } > > function MakeSuperRandom() > { > return srand( ( double ) microtime( time() ) * 10 ); > } > > function PickRandomImages( $array ) > { > $num1 = count( $array ); > $num1 = $num1 - 1; > MakeSuperRandom(); > > $img_num = rand( 3, $num1 ); > $image[] = $array[$img_num]; > > $num2 = count( $array ); > $num2 = $num2 - 1; > MakeSuperRandom(); > > $img_num = rand( 3, $num2 ); > $image[] = $array[$img_num]; > > $num3 = count( $array ); > $num3 = $num3 - 1; > MakeSuperRandom(); > > $img_num = rand( 3, $num3 ); > $image[] = $array[$img_num]; > return $image; > } > > function ChkArray( $array ) > { > if( ( empty( $array ) ) || ( count( $array ) > 3 ) ) { > $data = 1; > } else { > $data = 0; > } > return $data; > } > > function GeneratePrivKey( $array ) > { > if( empty( $array ) ) { > $data = GenerateError( "Missing data for GeneratePrivKey function." ); > } else { > for( $x = 0; $x < count( $array ); $x++ ) { >$keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); > } > for( $y = 0; $y < count( $keys ); $y++ ) { >if( count( $keys ) == $keys[$y] ) { > $data .= $keys[$y]; >} else { > $data .= $keys[$y] . ":"; >} > } > } > return $data; > } > > function GeneratePubKey( $data ) > { > return md5( $data ); > } > > function EncData( $data, $key ) > { > $td = mcrypt_module_open( 'rijndael-256', '', 'ofb', '' ); > $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_DEV_RANDOM ); > $ks = mcrypt_enc_get_key_size( $td ); > @mcrypt_generic_init( $td, $key, $iv ); > $encrypted = mcrypt_generic( $td, $data ); > echo "Ciphered Text using Random Image Hash as Key: " . > $encrypted . ""; > @mcrypt_generic_deinit( $td ); > @mcrypt_generic_init( $td, $key, $iv ); > $decrypted = mdecrypt_generic( $td, $encrypted ); > echo "De-Ciphered Text using Random Image Hash as Key:" > . $decrypted . ""; > @mcrypt_generic_deinit( $td ); > @mcrypt_module_close( $td ); > } > > // to use functions > $x = ReadFolder( "images/" ); > $y = PickRandomImages( $x ); > $b = GeneratePrivKey( $y ); > echo "Private Key data:" . $b . ""; > $d
Re: [PHP-DB] Credit Card Encryption
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Daniel Brown wrote: > On Dec 19, 2007 2:41 AM, Keith Spiller <[EMAIL PROTECTED]> wrote: >> Ok I've done some research and some thinking. What about storing orders in >> the database (product info and customer info) and then using GnuPG or PGP to >> send the credit card info to the merchant? This way the credit card >> information is not stored on the server or in the database but only in >> printed format by the merchant. Since my client processes all of the credit >> card orders by hand this seems like an ideal solution. > > I had a client that did offline (manual) processing of credit card > orders as well. With liability issues and the problems that others > have already pointed out, storing the credit card information was not > an option, yet my client still needed some way of having the data > available offline. > > Consider the following: > > ISSUERLENGTH > Diner's Club/Carte Blanche 14 > American Express 15 > VISA 13 or 16 > MasterCard16 > Discover 16 > > Security checks aside (like making sure they selected the type of > card and that it matched the algorithm - VISA beginning with 4 and > being strlen($_POST['cardnum']) == 13 or 16, MasterCard being 16, > beginning with 51xx to 55xx, et cetera), I then had a hybrid of > storage and delivery. > > Mail the first digits to the sales email > address(es) on file. Three addresses on two domains were used for > redundancy in this case. Store the remaining digits in the database. > You could write your own encryption algorithm or use one that is > publicly-available and reversible (Blowfish is what I was using, at > 128, key length of 56 lower ASCII characters, padded with 7 on the key > and four on the output - MD5, SHA1, et al are NOT options here). > > The sales department then received the first digits of the credit > card number via email, which stated it was an order key. Again, in my Using the order number as the key is bad practice. Here is a random key generator that you could use for your public/private keys and still use the blowfish cipher as your method of encrypting: 3 ) ) { $data = 1; } else { $data = 0; } return $data; } function GeneratePrivKey( $array ) { if( empty( $array ) ) { $data = GenerateError( "Missing data for GeneratePrivKey function." ); } else { for( $x = 0; $x < count( $array ); $x++ ) { $keys[] = mhash( MHASH_SHA1, sha1( $array[$x] ) ); } for( $y = 0; $y < count( $keys ); $y++ ) { if( count( $keys ) == $keys[$y] ) { $data .= $keys[$y]; } else { $data .= $keys[$y] . ":"; } } } return $data; } function GeneratePubKey( $data ) { return md5( $data ); } function EncData( $data, $key ) { $td = mcrypt_module_open( 'rijndael-256', '', 'ofb', '' ); $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_DEV_RANDOM ); $ks = mcrypt_enc_get_key_size( $td ); @mcrypt_generic_init( $td, $key, $iv ); $encrypted = mcrypt_generic( $td, $data ); echo "Ciphered Text using Random Image Hash as Key: " . $encrypted . ""; @mcrypt_generic_deinit( $td ); @mcrypt_generic_init( $td, $key, $iv ); $decrypted = mdecrypt_generic( $td, $encrypted ); echo "De-Ciphered Text using Random Image Hash as Key:" . $decrypted . ""; @mcrypt_generic_deinit( $td ); @mcrypt_module_close( $td ); } // to use functions $x = ReadFolder( "images/" ); $y = PickRandomImages( $x ); $b = GeneratePrivKey( $y ); echo "Private Key data:" . $b . ""; $data = "" . GeneratePubKey( $b ); echo "Public Key data:"; print_r( $data ); echo ""; echo EncData( $credit_card_data, $b ); ?> With that code you will have to re-write the 'EncData()' function to perform ONLY encryption as of right now it encrypts and decrypts for demonstration purposes only. And on another note why not use a different delivery method altogether such as using java-script to encrypt the data prior to transmission, store the private key inside the local network, use the public key and associate it with the purchase within the database and develop a method of authentication for the users to retrieve the data and then, and only then use the private key to decrypt the data. Just a thought. > case, I wrote an algorithm that would encrypt these digits prior to > sending, using the actual order number as a key. The accounting > software I wrote (all in PHP) would then retrieve the latter half of > the credit card number from the database, decrypt the first part of > the credit card number from the email (entered by the sales team on an > SSL-encrypted page), and the credit card number would be displayed in > full on the screen, to print, process, or verify. > > The downside is that, if there are any problems with email and > delivery, the first $n digits of the card might not be received by the > sales
Re: [PHP-DB] Credit Card Encryption
On Dec 19, 2007 2:41 AM, Keith Spiller <[EMAIL PROTECTED]> wrote: > Ok I've done some research and some thinking. What about storing orders in > the database (product info and customer info) and then using GnuPG or PGP to > send the credit card info to the merchant? This way the credit card > information is not stored on the server or in the database but only in > printed format by the merchant. Since my client processes all of the credit > card orders by hand this seems like an ideal solution. I had a client that did offline (manual) processing of credit card orders as well. With liability issues and the problems that others have already pointed out, storing the credit card information was not an option, yet my client still needed some way of having the data available offline. Consider the following: ISSUERLENGTH Diner's Club/Carte Blanche 14 American Express 15 VISA 13 or 16 MasterCard16 Discover 16 Security checks aside (like making sure they selected the type of card and that it matched the algorithm - VISA beginning with 4 and being strlen($_POST['cardnum']) == 13 or 16, MasterCard being 16, beginning with 51xx to 55xx, et cetera), I then had a hybrid of storage and delivery. Mail the first digits to the sales email address(es) on file. Three addresses on two domains were used for redundancy in this case. Store the remaining digits in the database. You could write your own encryption algorithm or use one that is publicly-available and reversible (Blowfish is what I was using, at 128, key length of 56 lower ASCII characters, padded with 7 on the key and four on the output - MD5, SHA1, et al are NOT options here). The sales department then received the first digits of the credit card number via email, which stated it was an order key. Again, in my case, I wrote an algorithm that would encrypt these digits prior to sending, using the actual order number as a key. The accounting software I wrote (all in PHP) would then retrieve the latter half of the credit card number from the database, decrypt the first part of the credit card number from the email (entered by the sales team on an SSL-encrypted page), and the credit card number would be displayed in full on the screen, to print, process, or verify. The downside is that, if there are any problems with email and delivery, the first $n digits of the card might not be received by the sales department. While, to date, I'm not aware of this having been a problem for my client (knock on wood), it's still a possibility. For this reason, you need to be sure to either have the email address confirmed prior to processing the order, or require a valid telephone number, so that you can reach the customer in the event of a failure. To assure the customer that you are calling legitimately, you will still have the last digits of the credit card, as well as the expiration data and CVV number (also stored in the database), the billing address, and the date and time the order was placed. It may not work for you, but that's how I created the system for my client in 2004, and it's still being used today, with almost $8 Million in online sales. [pats self on back] ;-P Now if I could just go back and renegotiate my contract for that gig -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Credit Card Encryption
Ok I've done some research and some thinking. What about storing orders in the database (product info and customer info) and then using GnuPG or PGP to send the credit card info to the merchant? This way the credit card information is not stored on the server or in the database but only in printed format by the merchant. Since my client processes all of the credit card orders by hand this seems like an ideal solution. What is more, the order and customer info do not need to be present in the encrypted emails. That way the email does not contain a customer name, but only an order id (which could even be a unique and hidden value stored via AES in the mysql db). What are your thoughts? Keith - Original Message - From: "Bastien Koert" <[EMAIL PROTECTED]> To: "Keith Spiller" <[EMAIL PROTECTED]>; Sent: Tuesday, December 18, 2007 9:41 PM Subject: RE: [PHP-DB] Credit Card Encryption Think very carefully about what you want to do here. PCI (payment card industry) has radically changed the rules about how CC data is stored in a networked environment. If your data environment is shared (shared web hosting), don't even think about it. There are a large number of rules that you need to follow to make your data systems PCI compliant [ http://www.pcicomplianceguide.org/ ] and they are not easy to follow. Things like strong encryption, code audits by qualified third parties etc. If you absolutely need to store the data (many of my large clients do this): 1. the database server should not be web facing, nor accessible internally by the web servers 2. the access (physical and electronic) should be extremely limited 3. the facility that holds the data should be hardened with limited controlled access 4. provide a cross reference number to the CC that other applications can use to replace the CC number If you are storing transactional data, just store the confirmation number that is returned by the payment gateway that you use. Let the payment gateway assume the risks of handling the data, its what they get paid for. If the data is for re-occurring payments, let the payment gateway handle it, many support these kinds of payments. Bastien From: [EMAIL PROTECTED]> To: php-db@lists.php.net> CC: [EMAIL PROTECTED]> Date: Tue, 18 Dec 2007 18:20:08 -0700> Subject: [PHP-DB] Credit Card Encryption> > Hi Everyone,> > I'm trying to determine the best method to store credit card numbers in a > mysql database. As yet I have been unable to determine whether I should use > MySQL AES, DES or a PHP encryption method. I would greatly appreciate any > advice you guys could offer.> > Thanks.> > Keith > > -- > PHP Database Mailing List (http://www.php.net/)> To unsubscribe, visit: http://www.php.net/unsub.php> _ Discover new ways to stay in touch with Windows Live! Visit the City @ Live today! http://getyourliveid.ca/?icid=LIVEIDENCA006 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Credit Card Encryption
Thanks for the information, especially the PCI Complancy link and info. Keith - Original Message - From: Bastien Koert To: Keith Spiller ; php-db@lists.php.net Sent: Tuesday, December 18, 2007 9:41 PM Subject: RE: [PHP-DB] Credit Card Encryption Think very carefully about what you want to do here. PCI (payment card industry) has radically changed the rules about how CC data is stored in a networked environment. If your data environment is shared (shared web hosting), don't even think about it. There are a large number of rules that you need to follow to make your data systems PCI compliant [ http://www.pcicomplianceguide.org/ ] and they are not easy to follow. Things like strong encryption, code audits by qualified third parties etc. If you absolutely need to store the data (many of my large clients do this): 1. the database server should not be web facing, nor accessible internally by the web servers 2. the access (physical and electronic) should be extremely limited 3. the facility that holds the data should be hardened with limited controlled access 4. provide a cross reference number to the CC that other applications can use to replace the CC number If you are storing transactional data, just store the confirmation number that is returned by the payment gateway that you use. Let the payment gateway assume the risks of handling the data, its what they get paid for. If the data is for re-occurring payments, let the payment gateway handle it, many support these kinds of payments. Bastien > From: [EMAIL PROTECTED] > To: php-db@lists.php.net > CC: [EMAIL PROTECTED] > Date: Tue, 18 Dec 2007 18:20:08 -0700 > Subject: [PHP-DB] Credit Card Encryption > > Hi Everyone, > > I'm trying to determine the best method to store credit card numbers in a > mysql database. As yet I have been unable to determine whether I should use > MySQL AES, DES or a PHP encryption method. I would greatly appreciate any > advice you guys could offer. > > Thanks. > > Keith > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- Books, DVD's, gadgets, music and more. Shop online with Sympatico / MSN Shopping today!
RE: [PHP-DB] Credit Card Encryption
Think very carefully about what you want to do here. PCI (payment card industry) has radically changed the rules about how CC data is stored in a networked environment. If your data environment is shared (shared web hosting), don't even think about it. There are a large number of rules that you need to follow to make your data systems PCI compliant [ http://www.pcicomplianceguide.org/ ] and they are not easy to follow. Things like strong encryption, code audits by qualified third parties etc. If you absolutely need to store the data (many of my large clients do this): 1. the database server should not be web facing, nor accessible internally by the web servers 2. the access (physical and electronic) should be extremely limited 3. the facility that holds the data should be hardened with limited controlled access 4. provide a cross reference number to the CC that other applications can use to replace the CC number If you are storing transactional data, just store the confirmation number that is returned by the payment gateway that you use. Let the payment gateway assume the risks of handling the data, its what they get paid for. If the data is for re-occurring payments, let the payment gateway handle it, many support these kinds of payments. Bastien > From: [EMAIL PROTECTED]> To: php-db@lists.php.net> CC: [EMAIL PROTECTED]> > Date: Tue, 18 Dec 2007 18:20:08 -0700> Subject: [PHP-DB] Credit Card > Encryption> > Hi Everyone,> > I'm trying to determine the best method to > store credit card numbers in a > mysql database. As yet I have been unable to > determine whether I should use > MySQL AES, DES or a PHP encryption method. I > would greatly appreciate any > advice you guys could offer.> > Thanks.> > > Keith > > -- > PHP Database Mailing List (http://www.php.net/)> To > unsubscribe, visit: http://www.php.net/unsub.php> _ Discover new ways to stay in touch with Windows Live! Visit the City @ Live today! http://getyourliveid.ca/?icid=LIVEIDENCA006
RE: [PHP-DB] Credit Card Encryption
And if you do store it, don't store it on the websderver. Make sure it's on another server behind another firewall. You don't want someone that hacks into your web server to have ready access to your database. I think AES is supposed to be the best, then 3DES is next. (That's 3DES, or triple DES, not DES) But like Chris said: if you don't have to, dont do it. But if you must, encrypt all of the personal information data points, not just the CC info. Gary > -Original Message- > From: Chris [mailto:[EMAIL PROTECTED] > Sent: Tue, December 18, 2007 9:30 PM > To: Keith Spiller > Cc: php-db@lists.php.net > Subject: Re: [PHP-DB] Credit Card Encryption > > > Keith Spiller wrote: > > Hi Everyone, > > > > I'm trying to determine the best method to store credit > card numbers in > > a mysql database. As yet I have been unable to determine whether I > > should use MySQL AES, DES or a PHP encryption method. I > would greatly > > appreciate any advice you guys could offer. > > Why do you need to store c/c info? If at all possible, don't. > > If you're looking for something like recurring payments, use > paypal or > one of the other payment providers that support it. > > > -- > Postgresql & php tutorials > http://www.designmagick.com/ > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Credit Card Encryption
Keith Spiller wrote: Hi Everyone, I'm trying to determine the best method to store credit card numbers in a mysql database. As yet I have been unable to determine whether I should use MySQL AES, DES or a PHP encryption method. I would greatly appreciate any advice you guys could offer. Why do you need to store c/c info? If at all possible, don't. If you're looking for something like recurring payments, use paypal or one of the other payment providers that support it. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php