Trimming comment bloat in Crypt class.
This commit is contained in:
parent
e5beda1d5b
commit
3c7dd2822b
|
@ -24,10 +24,6 @@ class Crypt {
|
||||||
*/
|
*/
|
||||||
public static function encrypt($value)
|
public static function encrypt($value)
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------
|
|
||||||
// Determine the input vector source. Different servers
|
|
||||||
// and operating systems will have varying options.
|
|
||||||
// -----------------------------------------------------
|
|
||||||
if (defined('MCRYPT_DEV_URANDOM'))
|
if (defined('MCRYPT_DEV_URANDOM'))
|
||||||
{
|
{
|
||||||
$random = MCRYPT_DEV_URANDOM;
|
$random = MCRYPT_DEV_URANDOM;
|
||||||
|
@ -41,21 +37,17 @@ public static function encrypt($value)
|
||||||
$random = MCRYPT_RAND;
|
$random = MCRYPT_RAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// The system random number generator must be seeded to produce random results.
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
$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 nice string value.
|
||||||
// We use base64 encoding to get a nice string value.
|
|
||||||
// -----------------------------------------------------
|
|
||||||
return base64_encode($iv.$value);
|
return base64_encode($iv.$value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +59,6 @@ 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)
|
||||||
|
@ -78,14 +66,10 @@ public static function decrypt($value)
|
||||||
throw new \Exception('Decryption error. Input value is not valid base64 data.');
|
throw new \Exception('Decryption error. Input value is not valid base64 data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
|
||||||
// Extract the input vector from the value.
|
// Extract the input vector from the value.
|
||||||
// -----------------------------------------------------
|
|
||||||
$iv = substr($value, 0, static::iv_size());
|
$iv = substr($value, 0, static::iv_size());
|
||||||
|
|
||||||
// -----------------------------------------------------
|
|
||||||
// Remove the input vector from the encrypted value.
|
// Remove the input vector from the encrypted value.
|
||||||
// -----------------------------------------------------
|
|
||||||
$value = substr($value, static::iv_size());
|
$value = substr($value, static::iv_size());
|
||||||
|
|
||||||
return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
|
return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
|
||||||
|
|
Loading…
Reference in New Issue