This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add phpseclib for pure-php implementation of legacy mcrypt-ed data. W…
…e have to switch to another block size for future.
- Loading branch information
Showing
3 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/src/core/src/pydio/Core/Utils/Crypto/ZeroPaddingRijndael.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2016 Abstrium <contact (at) pydio.com> | ||
* This file is part of Pydio. | ||
* | ||
* Pydio is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pydio is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pydio. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* The latest code can be found at <https://pydio.com/>. | ||
*/ | ||
|
||
namespace Pydio\Core\Utils\Crypto; | ||
|
||
defined('AJXP_EXEC') or die('Access not allowed'); | ||
|
||
use \phpseclib\Crypt\Rijndael; | ||
|
||
/** | ||
* Class ZeroPaddingRijndael | ||
* @package Pydio\Core\Utils\Crypto | ||
*/ | ||
class ZeroPaddingRijndael extends Rijndael { | ||
/** | ||
* Pads a string | ||
* | ||
* Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize. | ||
* $this->block_size - (strlen($text) % $this->block_size) bytes are added, each of which is equal to | ||
* chr($this->block_size - (strlen($text) % $this->block_size) | ||
* | ||
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless | ||
* and padding will, hence forth, be enabled. | ||
* | ||
* @see self::_unpad() | ||
* @param string $text | ||
* @throws \LengthException if padding is disabled and the plaintext's length is not a multiple of the block size | ||
* @access private | ||
* @return string | ||
*/ | ||
function _pad($text) | ||
{ | ||
$length = strlen($text); | ||
|
||
if (!$this->padding) { | ||
if ($length % $this->block_size == 0) { | ||
return $text; | ||
} else { | ||
throw new \LengthException("The plaintext's length ($length) is not a multiple of the block size ({$this->block_size}). Try enabling padding."); | ||
} | ||
} | ||
|
||
$pad = $this->block_size - ($length % $this->block_size); | ||
return str_pad($text, $length + $pad, "\0"); | ||
} | ||
/** | ||
* Unpads a string. | ||
* | ||
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong | ||
* and false will be returned. | ||
* | ||
* @see self::_pad() | ||
* @param string $text | ||
* @throws \LengthException if the ciphertext's length is not a multiple of the block size | ||
* @access private | ||
* @return string | ||
*/ | ||
function _unpad($text) { | ||
$trimed = trim($text, "\0"); | ||
while($text === $trimed){ | ||
$trimed = trim($text, "\0"); | ||
} | ||
return $trimed; | ||
} | ||
} |