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

Refactoring the crypt class.

parent bc51ec3d
...@@ -24,8 +24,7 @@ class Crypt { ...@@ -24,8 +24,7 @@ class Crypt {
*/ */
public static function encrypt($value) public static function encrypt($value)
{ {
// If the system random number generator is being used, we need to seed // Seed the system random number generator so it will produce random results.
// it to get adequately random results.
if (($random = static::randomizer()) === MCRYPT_RAND) mt_srand(); if (($random = static::randomizer()) === MCRYPT_RAND) mt_srand();
$iv = mcrypt_create_iv(static::iv_size(), $random); $iv = mcrypt_create_iv(static::iv_size(), $random);
...@@ -50,10 +49,8 @@ class Crypt { ...@@ -50,10 +49,8 @@ class Crypt {
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.
$iv = substr($value, 0, static::iv_size()); $iv = substr($value, 0, static::iv_size());
// 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");
...@@ -87,12 +84,9 @@ class Crypt { ...@@ -87,12 +84,9 @@ class Crypt {
*/ */
private static function key() private static function key()
{ {
if (is_null($key = Config::get('application.key')) or $key == '') if ( ! is_null($key = Config::get('application.key')) and $key !== '') return $key;
{
throw new \Exception("The encryption class can not be used without an encryption 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