Commit 1916e27d authored by Taylor Otwell's avatar Taylor Otwell

Refactoring the crypt class.

parent bc51ec3d
......@@ -24,8 +24,7 @@ class Crypt {
*/
public static function encrypt($value)
{
// If the system random number generator is being used, we need to seed
// it to get adequately random results.
// Seed the system random number generator so it will produce random results.
if (($random = static::randomizer()) === MCRYPT_RAND) mt_srand();
$iv = mcrypt_create_iv(static::iv_size(), $random);
......@@ -50,10 +49,8 @@ class Crypt {
throw new \Exception('Decryption error. Input value is not valid base64 data.');
}
// Extract the input vector from the value.
$iv = substr($value, 0, static::iv_size());
// Remove the input vector from the encrypted value.
$value = substr($value, static::iv_size());
return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
......@@ -87,12 +84,9 @@ class Crypt {
*/
private static function key()
{
if (is_null($key = Config::get('application.key')) or $key == '')
{
throw new \Exception("The encryption class can not be used without an encryption key.");
}
if ( ! is_null($key = Config::get('application.key')) and $key !== '') return $key;
return $key;
throw new \Exception("The encryption class can not be used without an encryption key.");
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment