refactoring various pieces of the framework.

This commit is contained in:
Taylor Otwell
2011-10-18 20:19:36 -05:00
parent e985057b4c
commit 9fc9f88a41
18 changed files with 193 additions and 114 deletions

View File

@@ -72,25 +72,29 @@ class Crypter {
*/
public static function decrypt($value)
{
// Since all encrypted strings generated by this class are base64
// encoded, we will first attempt to base64 decode the string.
// If we can't do it, we'll bail out.
if ( ! is_string($value = base64_decode($value, true)))
{
throw new \Exception('Decryption error. Input value is not valid base64 data.');
}
// Extract the input vector and the encrypted string from the value.
// These will be used by Mcrypt to properly decrypt the value.
$iv = substr($value, 0, static::iv_size());
$value = substr($value, static::iv_size());
list($iv, $value) = static::parse($value);
$key = Config::$items['application']['key'];
return rtrim(mcrypt_decrypt(static::$cipher, $key, $value, static::$mode, $iv), "\0");
}
/**
* Parse an encrypted value into the input vector and the actual value.
*
* @param string $value
* @return array
*/
protected static function parse($value)
{
return array(substr($value, 0, static::iv_size()), substr($value, static::iv_size()));
}
/**
* Get the input vector size for the cipher and mode.
*