Hello, world!
I am designing a web store. It will have each user's payment info (eg, credit card number), and I need a way to keep it safe. How is this usually done?
Thanks!
[SOLVED]E-commerce » encrypt user data
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
[SOLVED]E-commerce » encrypt user data
Last edited by Jonah Bron on Fri Feb 15, 2008 3:39 pm, edited 1 time in total.
Re: E-commerce » encrypt user data
Write it down, put it in a safe and delete it from the server.
Seriously though, most will tell you to not store this data on the server to avert the risk of it being compromised and to reduce your liability. If someone compromises the security of your server, they will more than likely be able to discover the encryption keys to decrypt it anyway.
Seriously though, most will tell you to not store this data on the server to avert the risk of it being compromised and to reduce your liability. If someone compromises the security of your server, they will more than likely be able to discover the encryption keys to decrypt it anyway.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: E-commerce » encrypt user data
Hmmm.
Well, what info would you suggest that I keep saved, and what to make the user put in each time?
Well, what info would you suggest that I keep saved, and what to make the user put in each time?
Re: E-commerce » encrypt user data
I would have them enter their credit card number and CVV/CVC code on every purchase at the bare minimum.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: E-commerce » encrypt user data
Okay, thanks.
Re: [SOLVED]E-commerce » encrypt user data
If you process their transaction in real-time, through a payment gateway, you don't necessarily need to keep their card info & that is probably the safest way, not least for your piece of mind.
If you require more freedom, perhaps the order needs customisation, approval or security checks before being processed, then you will need to store the info.
When storing card info, you gain a great deal of power for reducing fraud, but with it comes responsibility for safeguarding the info. Stored card info lets you compare against previous transactions in your database & you can build a risk assessment system.
One way of securing card info, such as the card number, is to encrypt it. There are a variety of ways to do this & the more complex the encryption the better.
I would suggest you don't take my example as your real world technique, but here is one way you could do it.
Please mix it up or add some more levels of complexity if you do use it. (ie, i just posted it, so ppl will take it as an example)
Take each part of the card number & apply a secret maths puzzle to it that can be reversed.
An point to note here is that you should apply your personal encryption right away, so as soon as the user posts the info, you encrypt.
Say the first part of the card number is 1234 ($card1)
We made a sum with the card number & appended the random keys on the end.
So, lets say $rand1 is 130 & $rand2 is 285
Now, you know
that the last 3 digits are $rand2 & the 3 digits before that are $rand1, the remaining digits is the sum, $x.
You can now reconstruct the real number.
$card_num = $x / ($rand2-$rand1);
// 191270 / (285-130) = 1234
Get creative, split up your rand nums, [$rand1 = char 2,5 & 9] .... use md5(), use random chars, key phrases, etc etc
IMO, the best solution is to use a combination of established encryption & your own personal creative stuff.
I'm no expert, but I think these techniques are more than most people implement.
If you require more freedom, perhaps the order needs customisation, approval or security checks before being processed, then you will need to store the info.
When storing card info, you gain a great deal of power for reducing fraud, but with it comes responsibility for safeguarding the info. Stored card info lets you compare against previous transactions in your database & you can build a risk assessment system.
One way of securing card info, such as the card number, is to encrypt it. There are a variety of ways to do this & the more complex the encryption the better.
I would suggest you don't take my example as your real world technique, but here is one way you could do it.
Please mix it up or add some more levels of complexity if you do use it. (ie, i just posted it, so ppl will take it as an example)
Take each part of the card number & apply a secret maths puzzle to it that can be reversed.
An point to note here is that you should apply your personal encryption right away, so as soon as the user posts the info, you encrypt.
Say the first part of the card number is 1234 ($card1)
Code: Select all
$rand1=rand(101,199);
$rand2=rand(201,299);
$encrypt = ( ($card1 * $rand2 ) - ( $card1 * $rand1 ) ) .$rand1.$rand2;
So, lets say $rand1 is 130 & $rand2 is 285
The actual sum is 191270 & the $rand's are 130 & 285 on the end of that number( (1234 * 285) - (1234 * 130) ).130.285
-> ( (351690) - (160420) ).130.285
-> 191270.130.285
== 191270130285
Now, you know
You can now reconstruct the real number.
$card_num = $x / ($rand2-$rand1);
// 191270 / (285-130) = 1234
Code: Select all
// decrypt
$rand1=substr($encrypt,-6,3);
$rand2=substr($encrypt,-3);
$x=substr($encrypt,-6);
$card_num = $x / ($rand2-$rand1);
IMO, the best solution is to use a combination of established encryption & your own personal creative stuff.
I'm no expert, but I think these techniques are more than most people implement.