refactoring crypt class.
This commit is contained in:
parent
6e93237ec9
commit
77d65b89cb
|
@ -24,21 +24,8 @@ class Crypt {
|
||||||
*/
|
*/
|
||||||
public static function encrypt($value)
|
public static function encrypt($value)
|
||||||
{
|
{
|
||||||
if (defined('MCRYPT_DEV_URANDOM'))
|
// Seed the system random number generator if it is being used.
|
||||||
{
|
if (($random = static::randomizer()) === MCRYPT_RAND)
|
||||||
$random = MCRYPT_DEV_URANDOM;
|
|
||||||
}
|
|
||||||
elseif (defined('MCRYPT_DEV_RANDOM'))
|
|
||||||
{
|
|
||||||
$random = MCRYPT_DEV_RANDOM;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$random = MCRYPT_RAND;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The system random number generator must be seeded to produce random results.
|
|
||||||
if ($random === MCRYPT_RAND)
|
|
||||||
{
|
{
|
||||||
mt_srand();
|
mt_srand();
|
||||||
}
|
}
|
||||||
|
@ -47,7 +34,6 @@ public static function encrypt($value)
|
||||||
|
|
||||||
$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.
|
|
||||||
return base64_encode($iv.$value);
|
return base64_encode($iv.$value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +62,28 @@ public static function decrypt($value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the application key.
|
* Get the random number source that should be used for the OS.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private static function randomizer()
|
||||||
|
{
|
||||||
|
if (defined('MCRYPT_DEV_URANDOM'))
|
||||||
|
{
|
||||||
|
return MCRYPT_DEV_URANDOM;
|
||||||
|
}
|
||||||
|
elseif (defined('MCRYPT_DEV_RANDOM'))
|
||||||
|
{
|
||||||
|
return MCRYPT_DEV_RANDOM;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return MCRYPT_RAND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the application key from the application configuration file.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue