Commit 80f810de authored by Taylor Otwell's avatar Taylor Otwell

refactoring the crypter class.

parent 8d3151b1
......@@ -19,7 +19,7 @@ class Crypter {
*
* @var string
*/
protected static $mode = 'cbc';
protected static $mode = MCRYPT_MODE_CBC;
/**
* Encrypt a string using Mcrypt.
......@@ -37,30 +37,13 @@ class Crypter {
*/
public static function encrypt($value)
{
$iv = mcrypt_create_iv(static::iv_size(), static::randomizer());
$iv = mcrypt_create_iv(static::iv_size(), MCRYPT_RAND);
$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
return base64_encode($iv.$value);
}
/**
* Get the random number generator appropriate for the server.
*
* There are a variety of sources to get a random number; however, not all
* of them will be available on every server. We will attempt to use the
* most secure random number generator available.
*
* @return int
*/
protected static function randomizer()
{
foreach (array('MCRYPT_DEV_URANDOM', 'MCRYPT_DEV_RANDOM', 'MCRYPT_RAND') as $generator)
{
if (defined($generator)) return constant($generator);
}
}
/**
* Decrypt a string using Mcrypt.
*
......
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