TYPO3 CMS  TYPO3_7-6
AbstractSalt.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 abstract class AbstractSalt
22 {
30  abstract protected function applySettingsToSalt($salt);
31 
37  abstract protected function getGeneratedSalt();
38 
44  abstract protected function getItoa64();
45 
51  abstract protected function getSetting();
52 
60  public function base64Encode($input, $count)
61  {
62  $output = '';
63  $i = 0;
64  $itoa64 = $this->getItoa64();
65  do {
66  $value = ord($input[$i++]);
67  $output .= $itoa64[$value & 63];
68  if ($i < $count) {
69  $value |= ord($input[$i]) << 8;
70  }
71  $output .= $itoa64[$value >> 6 & 63];
72  if ($i++ >= $count) {
73  break;
74  }
75  if ($i < $count) {
76  $value |= ord($input[$i]) << 16;
77  }
78  $output .= $itoa64[$value >> 12 & 63];
79  if ($i++ >= $count) {
80  break;
81  }
82  $output .= $itoa64[$value >> 18 & 63];
83  } while ($i < $count);
84  return $output;
85  }
86 
94  protected function getLengthBase64FromBytes($byteLength)
95  {
96  // Calculates bytes in bits in base64
97  return (int)ceil($byteLength * 8 / 6);
98  }
99 }