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
ab5ce2a7
Commit
ab5ce2a7
authored
Feb 16, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added pkcs7 compliant padding to encryption class instead of default 0 padding.
parent
49d96669
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletion
+38
-1
crypter.php
laravel/crypter.php
+38
-1
No files found.
laravel/crypter.php
View file @
ab5ce2a7
...
...
@@ -16,6 +16,13 @@ class Crypter {
*/
public
static
$mode
=
MCRYPT_MODE_CBC
;
/**
* The block size of the cipher.
*
* @var int
*/
public
static
$block
=
32
;
/**
* Encrypt a string using Mcrypt.
*
...
...
@@ -28,6 +35,8 @@ class Crypter {
{
$iv
=
mcrypt_create_iv
(
static
::
iv_size
(),
static
::
randomizer
());
$value
=
static
::
pad
(
$value
);
$value
=
mcrypt_encrypt
(
static
::
$cipher
,
static
::
key
(),
$value
,
static
::
$mode
,
$iv
);
return
base64_encode
(
$iv
.
$value
);
...
...
@@ -55,7 +64,9 @@ class Crypter {
// so we will trim all of the padding characters.
$key
=
static
::
key
();
return
rtrim
(
mcrypt_decrypt
(
static
::
$cipher
,
$key
,
$value
,
static
::
$mode
,
$iv
),
"
\0
"
);
$value
=
mcrypt_decrypt
(
static
::
$cipher
,
$key
,
$value
,
static
::
$mode
,
$iv
);
return
static
::
unpad
(
$value
);
}
/**
...
...
@@ -97,6 +108,32 @@ class Crypter {
return
mcrypt_get_iv_size
(
static
::
$cipher
,
static
::
$mode
);
}
/**
* Add PKCS7 compatible padding on the given value.
*
* @param string $value
* @return string
*/
protected
static
function
pad
(
$value
)
{
$pad
=
static
::
$block
-
(
Str
::
length
(
$value
)
%
static
::
$block
);
return
$value
.=
str_repeat
(
chr
(
$pad
),
$pad
);
}
/**
* Remove the PKCS7 compatible padding from the given value.
*
* @param string $value
* @return string
*/
protected
static
function
unpad
(
$value
)
{
$pad
=
ord
(
$value
[(
$length
=
Str
::
length
(
$value
))
-
1
]);
return
substr
(
$value
,
0
,
$length
-
$pad
);
}
/**
* Get the encryption key from the application configuration.
*
...
...
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