Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
4c4ffa1d
Commit
4c4ffa1d
authored
Aug 16, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new crypter class to replace static crypt methods.
parent
b6720eb7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
18 deletions
+60
-18
aliases.php
application/config/aliases.php
+1
-1
changelog.md
changelog.md
+2
-1
crypter.php
system/crypter.php
+38
-13
cookie.php
system/session/cookie.php
+19
-3
No files found.
application/config/aliases.php
View file @
4c4ffa1d
...
...
@@ -24,7 +24,7 @@ return array(
'Cache'
=>
'System\\Cache'
,
'Config'
=>
'System\\Config'
,
'Cookie'
=>
'System\\Cookie'
,
'Crypt
'
=>
'System\\Crypt
'
,
'Crypt
er'
=>
'System\\Crypter
'
,
'DB'
=>
'System\\DB'
,
'Eloquent'
=>
'System\\DB\\Eloquent\\Model'
,
'File'
=>
'System\\File'
,
...
...
changelog.md
View file @
4c4ffa1d
...
...
@@ -3,4 +3,5 @@
## Version 1.6.0
-
Moved
**system/db/manager.php**
to
**system/db.php**
. Updated alias appropriately.
-
Unspecified optional parameters will be removed from URLs generated using route names.
\ No newline at end of file
-
Unspecified optional parameters will be removed from URLs generated using route names.
-
Fixed bug in Config::set that prevented it from digging deep into arrays.
\ No newline at end of file
system/crypt.php
→
system/crypt
er
.php
View file @
4c4ffa1d
<?php
namespace
System
;
class
Crypt
{
class
Crypt
er
{
/**
* The encryption cipher.
*
* @var string
*/
public
static
$cipher
=
'rijndael-256'
;
public
$cipher
;
/**
* The encryption mode.
*
* @var string
*/
public
static
$mode
=
'cbc'
;
public
$mode
;
/**
* Create a new Crypter instance.
*
* @param string $cipher
* @param string $mode
* @return void
*/
public
function
__construct
(
$cipher
=
'rijndael-256'
,
$mode
=
'cbc'
)
{
$this
->
cipher
=
$cipher
;
$this
->
mode
=
$mode
;
}
/**
* Create a new Crypter instance.
*
* @param string $cipher
* @param string $mode
* @return Crypt
*/
public
static
function
make
(
$cipher
=
'rijndael-256'
,
$mode
=
'cbc'
)
{
return
new
static
(
$cipher
,
$mode
);
}
/**
* Encrypt a value using the MCrypt library.
...
...
@@ -22,11 +47,11 @@ class Crypt {
* @param string $value
* @return string
*/
public
static
function
encrypt
(
$value
)
public
function
encrypt
(
$value
)
{
$iv
=
mcrypt_create_iv
(
static
::
iv_size
(),
static
::
randomizer
());
$iv
=
mcrypt_create_iv
(
$this
->
iv_size
(),
$this
->
randomizer
());
return
base64_encode
(
$iv
.
mcrypt_encrypt
(
static
::
$cipher
,
static
::
key
(),
$value
,
static
::
$
mode
,
$iv
));
return
base64_encode
(
$iv
.
mcrypt_encrypt
(
$this
->
cipher
,
$this
->
key
(),
$value
,
$this
->
mode
,
$iv
));
}
/**
...
...
@@ -34,7 +59,7 @@ class Crypt {
*
* @return int
*/
protected
static
function
randomizer
()
protected
function
randomizer
()
{
if
(
defined
(
'MCRYPT_DEV_URANDOM'
))
{
...
...
@@ -54,16 +79,16 @@ class Crypt {
* @param string $value
* @return string
*/
public
static
function
decrypt
(
$value
)
public
function
decrypt
(
$value
)
{
if
(
!
is_string
(
$value
=
base64_decode
(
$value
,
true
)))
{
throw
new
\Exception
(
'Decryption error. Input value is not valid base64 data.'
);
}
list
(
$iv
,
$value
)
=
array
(
substr
(
$value
,
0
,
static
::
iv_size
()),
substr
(
$value
,
static
::
iv_size
()));
list
(
$iv
,
$value
)
=
array
(
substr
(
$value
,
0
,
$this
->
iv_size
()),
substr
(
$value
,
$this
->
iv_size
()));
return
rtrim
(
mcrypt_decrypt
(
static
::
$cipher
,
static
::
key
(),
$value
,
static
::
$
mode
,
$iv
),
"
\0
"
);
return
rtrim
(
mcrypt_decrypt
(
$this
->
cipher
,
$this
->
key
(),
$value
,
$this
->
mode
,
$iv
),
"
\0
"
);
}
/**
...
...
@@ -71,7 +96,7 @@ class Crypt {
*
* @return string
*/
private
static
function
key
()
private
function
key
()
{
if
(
!
is_null
(
$key
=
Config
::
get
(
'application.key'
))
and
$key
!==
''
)
return
$key
;
...
...
@@ -85,9 +110,9 @@ class Crypt {
*
* @return int
*/
private
static
function
iv_size
()
private
function
iv_size
()
{
return
mcrypt_get_iv_size
(
static
::
$cipher
,
static
::
$
mode
);
return
mcrypt_get_iv_size
(
$this
->
cipher
,
$this
->
mode
);
}
}
\ No newline at end of file
system/session/cookie.php
View file @
4c4ffa1d
<?php
namespace
System\Session
;
use
System\Crypt
;
use
System\Config
;
use
System\Crypter
;
class
Cookie
implements
Driver
{
/**
* The Crypter instance.
*
* @var Crypter
*/
private
$crypter
;
/**
* Create a new Cookie session driver instance.
*
* @return void
*/
public
function
__construct
()
{
$this
->
crypter
=
new
Crypter
;
if
(
Config
::
get
(
'application.key'
)
==
''
)
{
throw
new
\Exception
(
"You must set an application key before using the Cookie session driver."
);
...
...
@@ -23,7 +37,7 @@ class Cookie implements Driver {
{
if
(
\System\Cookie
::
has
(
'session_payload'
))
{
return
unserialize
(
Crypt
::
decrypt
(
\System\Cookie
::
get
(
'session_payload'
)));
return
unserialize
(
$this
->
crypter
->
decrypt
(
\System\Cookie
::
get
(
'session_payload'
)));
}
}
...
...
@@ -39,7 +53,9 @@ class Cookie implements Driver {
{
extract
(
Config
::
get
(
'session'
));
\System\Cookie
::
put
(
'session_payload'
,
Crypt
::
encrypt
(
serialize
(
$session
)),
$lifetime
,
$path
,
$domain
,
$https
,
$http_only
);
$payload
=
$this
->
crypter
->
encrypt
(
serialize
(
$session
));
\System\Cookie
::
put
(
'session_payload'
,
$payload
,
$lifetime
,
$path
,
$domain
,
$https
,
$http_only
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment