Prev | Current Page 601 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


At the end, the encrypted string is transformed into hexadecimal format, which is easier to work with (for example,
to save in the database or in a configuration file):
// Convert $binary_encrypted_string to hexadecimal format
$hexa_encrypted_string = bin2hex($binary_encrypted_string);
The Decrypt() method is similar to the Encrypt() method. First you need the IV to be in a binary form (the
same first step you took in the Encrypt() method).
As the Encrypt() method returns the encrypted string as a hexadecimal string, the input parameter of
Decrypt() is also a hexadecimal string. You must convert this string to a byte array, which is the format
that mcrypt_decrypt() needs:
// Convert string in hexadecimal to byte array
$binary_encrypted_string = pack('H*', $encryptedString);
// Decrypt $binary_encrypted_string
$decrypted_string = mcrypt_decrypt(
self::$_msCipherAlgorithm,
self::$_msSecretKey,
$binary_encrypted_string,
MCRYPT_MODE_CBC,
$binary_iv);
return $decrypted_string;
The test_encryption.php test file for this class simply encrypts and decrypts data, demonstrating that things
are working properly. The code for this is very simple, so we won??™t detail it here.
Now that you have the SymmetricCrypt class code, the last step in creating the security-related classes is to
add the SecureCard class.
CHAPTER 16 ?–  MANAGING CUSTOMER DETAILS 489
Storing Credit Cart Information Using the SecureCard Class
In the following exercise, you??™ll build the SecureCard class, which represents the credit card of
a customer.


Pages:
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
Władysławowo noclegi pity pozycjonowanie bilety lotnicze świnoujście noclegi