improve crypt class comments.
This commit is contained in:
parent
fb66bf532d
commit
825ac35a47
|
@ -25,7 +25,8 @@ class Crypt {
|
||||||
public static function encrypt($value)
|
public static function encrypt($value)
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Determine the input vector source.
|
// Determine the input vector source. Different servers
|
||||||
|
// and operating systems will have varying options.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
if (defined('MCRYPT_DEV_URANDOM'))
|
if (defined('MCRYPT_DEV_URANDOM'))
|
||||||
{
|
{
|
||||||
|
@ -41,21 +42,19 @@ public static function encrypt($value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// The system random number generator must be seeded.
|
// The system random number generator must be seeded
|
||||||
|
// to produce adequately random results.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
if ($random === MCRYPT_RAND)
|
if ($random === MCRYPT_RAND)
|
||||||
{
|
{
|
||||||
mt_srand();
|
mt_srand();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
|
||||||
// Create the Mcrypt input vector and encrypt the value.
|
|
||||||
// -----------------------------------------------------
|
|
||||||
$iv = mcrypt_create_iv(static::iv_size(), $random);
|
$iv = mcrypt_create_iv(static::iv_size(), $random);
|
||||||
$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
|
$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Use base64 encoding to get a string value.
|
// We use base64 encoding to get a nice string value.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
return base64_encode($iv.$value);
|
return base64_encode($iv.$value);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +67,10 @@ public static function encrypt($value)
|
||||||
*/
|
*/
|
||||||
public static function decrypt($value)
|
public static function decrypt($value)
|
||||||
{
|
{
|
||||||
|
// -----------------------------------------------------
|
||||||
|
// Since all of our encrypted values are base64 encoded,
|
||||||
|
// we will decode the value here and verify it.
|
||||||
|
// -----------------------------------------------------
|
||||||
$value = base64_decode($value, true);
|
$value = base64_decode($value, true);
|
||||||
|
|
||||||
if ( ! $value)
|
if ( ! $value)
|
||||||
|
@ -81,7 +84,7 @@ public static function decrypt($value)
|
||||||
$iv = substr($value, 0, static::iv_size());
|
$iv = substr($value, 0, static::iv_size());
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Remove the input vector from the value.
|
// Remove the input vector from the encrypted value.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
$value = substr($value, static::iv_size());
|
$value = substr($value, static::iv_size());
|
||||||
|
|
||||||
|
@ -106,6 +109,8 @@ private static function key()
|
||||||
/**
|
/**
|
||||||
* Get the input vector size for the cipher and mode.
|
* Get the input vector size for the cipher and mode.
|
||||||
*
|
*
|
||||||
|
* Different ciphers and modes use varying lengths of input vectors.
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private static function iv_size()
|
private static function iv_size()
|
||||||
|
|
Loading…
Reference in New Issue