| @@ 268-289 (lines=22) @@ | ||
| 265 | * @param int $keyLength |
|
| 266 | * @return string |
|
| 267 | */ |
|
| 268 | private function computeOwnerEntry($ownerPassword, $userPassword, $revision, $keyLength) |
|
| 269 | { |
|
| 270 | $hash = hex2bin(md5(substr($ownerPassword . self::ENCRYPTION_PADDING, 0, 32))); |
|
| 271 | ||
| 272 | if ($revision >= 3) { |
|
| 273 | for ($i = 0; $i < 50; ++$i) { |
|
| 274 | $hash = hex2bin(md5($hash)); |
|
| 275 | } |
|
| 276 | ||
| 277 | $key = substr($hash, 0, $keyLength); |
|
| 278 | } else { |
|
| 279 | $key = substr($hash, 0, 5); |
|
| 280 | } |
|
| 281 | ||
| 282 | $value = openssl_encrypt(substr($userPassword . self::ENCRYPTION_PADDING, 0, 32), 'rc-4', $key); |
|
| 283 | ||
| 284 | if ($revision >= 3) { |
|
| 285 | $value = self::applyRc4Loop($value, $key, $keyLength); |
|
| 286 | } |
|
| 287 | ||
| 288 | return $value; |
|
| 289 | } |
|
| 290 | ||
| 291 | /** |
|
| 292 | * Computes the user entry (rev 2) as defined by algorithm 3.4 in 3.5.2. |
|
| @@ 77-98 (lines=22) @@ | ||
| 74 | * @param int $keyLength |
|
| 75 | * @return string |
|
| 76 | */ |
|
| 77 | public static function computeOwnerEntry($ownerPassword, $userPassword, $revision, $keyLength) |
|
| 78 | { |
|
| 79 | $hash = hex2bin(md5(substr($ownerPassword . self::ENCRYPTION_PADDING, 0, 32))); |
|
| 80 | ||
| 81 | if ($revision >= 3) { |
|
| 82 | for ($i = 0; $i < 50; ++$i) { |
|
| 83 | $hash = hex2bin(md5($hash)); |
|
| 84 | } |
|
| 85 | ||
| 86 | $key = substr($hash, 0, $keyLength); |
|
| 87 | } else { |
|
| 88 | $key = substr($hash, 0, 5); |
|
| 89 | } |
|
| 90 | ||
| 91 | $value = self::rc4($key, substr($userPassword . self::ENCRYPTION_PADDING, 0, 32)); |
|
| 92 | ||
| 93 | if ($revision >= 3) { |
|
| 94 | $value = self::applyRc4Loop($value, $key, $keyLength); |
|
| 95 | } |
|
| 96 | ||
| 97 | return $value; |
|
| 98 | } |
|
| 99 | ||
| 100 | /** |
|
| 101 | * Computes the user entry (rev 2) as defined by algorithm 3.4 in 3.5.2. |
|