Prev | Current Page 600 | Next

Emilian Balanescu and Cristian Darie

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

The IV should be exactly 16 bytes long for AES and will be kept as
a hexadecimal string (2 ?— 16 = 32 chars long). Both $_msSecretKey and $_msHexaIv variables are set to temporary
values here. They could just as easily take any other values, depending on the key you want to use.
Encrypt() starts by converting the IV from its hexadecimal value to a byte array because this is the format
expected by the mcrypt_encrypt() function (the one that does the actual encryption):
CHAPTER 16 ?–  MANAGING CUSTOMER DETAILS 488
// Pack SymmetricCrypt::_msHexaIv into a binary string
$binary_iv = pack('H*', self::$_msHexaIv);
The conversion is done using PHP??™s pack() function (learn more about it at http://www.php.net/pack).
The call to mcrypt_encrypt() follows:
// Encrypt $plainString
$binary_encrypted_string = mcrypt_encrypt(
self::$_msCipherAlgorithm,
self::$_msSecretKey,
$plainString,
MCRYPT_MODE_CBC,
$binary_iv);
This is the call that performs the actual encryption. Its parameters are obvious, and you can find more detail about
the mcrypt_encrypt() function at http://www.php.net/mcrypt. The MCRYPT_MODE_CBC specifies the
???cipher block chaining??? encryption method; this method uses a chaining mechanism in which the encryption of
each block of data depends on the encryption results of preceding blocks, except for the first block in which the IV
is used instead.


Pages:
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
botox Kraków wyświetlacz xperia Wczasy nad morzem baseny ogrodowe tłumacz niemieckiego