Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletions
+38
-1
laravel/crypter.php
+38
-1
No files found.
laravel/crypter.php
View file @
ab5ce2a7
...
@@ -17,6 +17,13 @@ class Crypter {
...
@@ -17,6 +17,13 @@ class Crypter {
public
static
$mode
=
MCRYPT_MODE_CBC
;
public
static
$mode
=
MCRYPT_MODE_CBC
;
/**
/**
* The block size of the cipher.
*
* @var int
*/
public
static
$block
=
32
;
/**
* Encrypt a string using Mcrypt.
* Encrypt a string using Mcrypt.
*
*
* The string will be encrypted using the AES-256 scheme and will be base64 encoded.
* The string will be encrypted using the AES-256 scheme and will be base64 encoded.
...
@@ -28,6 +35,8 @@ class Crypter {
...
@@ -28,6 +35,8 @@ class Crypter {
{
{
$iv
=
mcrypt_create_iv
(
static
::
iv_size
(),
static
::
randomizer
());
$iv
=
mcrypt_create_iv
(
static
::
iv_size
(),
static
::
randomizer
());
$value
=
static
::
pad
(
$value
);
$value
=
mcrypt_encrypt
(
static
::
$cipher
,
static
::
key
(),
$value
,
static
::
$mode
,
$iv
);
$value
=
mcrypt_encrypt
(
static
::
$cipher
,
static
::
key
(),
$value
,
static
::
$mode
,
$iv
);
return
base64_encode
(
$iv
.
$value
);
return
base64_encode
(
$iv
.
$value
);
...
@@ -55,7 +64,9 @@ class Crypter {
...
@@ -55,7 +64,9 @@ class Crypter {
// so we will trim all of the padding characters.
// so we will trim all of the padding characters.
$key
=
static
::
key
();
$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
);
}
}
/**
/**
...
@@ -98,6 +109,32 @@ class Crypter {
...
@@ -98,6 +109,32 @@ class Crypter {
}
}
/**
/**
* 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.
* Get the encryption key from the application configuration.
*
*
* @return string
* @return string
...
...
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