$encrypted_data . '
';
$our_card = new SecureCard();
try
{
$our_card->LoadEncryptedDataAndDecrypt($encrypted_data);
echo '
Decrypted data:
' .
$our_card->CardHolder . ', ' . $our_card->CardNumber . ', ' .
$our_card->IssueDate . ', ' . $our_card->ExpiryDate . ', ' .
$our_card->IssueNumber . ', ' . $our_card->CardType;
}
catch(Exception $e)
{
echo '
Exception: ' . $e->getMessage() . '';
exit();
}
?>
3. Load test_card.php file in your favorite browser to see the results (see Figure 16-3). You can change the
data from this file as you want.
CHAPTER 16 ?– MANAGING CUSTOMER DETAILS 494
Figure 16-3. Encrypting and decrypting credit card information
How It Works: The SecureCard Class
There??™s a bit more code here than in previous examples, but it??™s all quite simple. First you have the private member
variables to hold the card details as individual strings, as an encrypted string, and in an intermediate XML document.
You also have Boolean flags indicating whether the data has been successfully encrypted or decrypted:
// Represents a credit card
class SecureCard
{
// Private members containing credit card's details
private $_mIsDecrypted = false;
private $_mIsEncrypted = false;
private $_mCardHolder;
private $_mCardNumber;
private $_mIssueDate;
private $_mExpiryDate;
private $_mIssueNumber;
private $_mCardType;
private $_mEncryptedData;
private $_mXmlCardData;
Next you have two important public methods.
Pages:
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616