@@ 228-257 (lines=30) @@ | ||
225 | * @param bool $encryptMetadata |
|
226 | * @return string |
|
227 | */ |
|
228 | private function computeEncryptionKey( |
|
229 | $password, |
|
230 | $revision, |
|
231 | $keyLength, |
|
232 | $ownerEntry, |
|
233 | $permissions, |
|
234 | $idEntry, |
|
235 | $encryptMetadata = true |
|
236 | ) { |
|
237 | $string = substr($password . self::ENCRYPTION_PADDING, 0, 32) |
|
238 | . $ownerEntry |
|
239 | . pack('V', $permissions) |
|
240 | . $idEntry; |
|
241 | ||
242 | if ($revision >= 4 && $encryptMetadata) { |
|
243 | $string .= "\0xff\0xff\0xff\0xff"; |
|
244 | } |
|
245 | ||
246 | $hash = hex2bin(md5($string)); |
|
247 | ||
248 | if ($revision >= 3) { |
|
249 | for ($i = 0; $i < 50; ++$i) { |
|
250 | $hash = hex2bin(md5(substr($hash, 0, $keyLength))); |
|
251 | } |
|
252 | ||
253 | return substr($hash, 0, $keyLength); |
|
254 | } |
|
255 | ||
256 | return substr($hash, 0, 5); |
|
257 | } |
|
258 | ||
259 | /** |
|
260 | * Computes the owner entry as defined by algorithm 3.3 in 3.5.2. |
@@ 37-66 (lines=30) @@ | ||
34 | * @param bool $encryptMetadata |
|
35 | * @return string |
|
36 | */ |
|
37 | public static function computeEncryptionKey( |
|
38 | $password, |
|
39 | $revision, |
|
40 | $keyLength, |
|
41 | $ownerEntry, |
|
42 | $permissions, |
|
43 | $idEntry, |
|
44 | $encryptMetadata = true |
|
45 | ) { |
|
46 | $string = substr($password . self::ENCRYPTION_PADDING, 0, 32) |
|
47 | . $ownerEntry |
|
48 | . pack('V', $permissions) |
|
49 | . $idEntry; |
|
50 | ||
51 | if ($revision >= 4 && $encryptMetadata) { |
|
52 | $string .= "\0xff\0xff\0xff\0xff"; |
|
53 | } |
|
54 | ||
55 | $hash = hex2bin(md5($string)); |
|
56 | ||
57 | if ($revision >= 3) { |
|
58 | for ($i = 0; $i < 50; ++$i) { |
|
59 | $hash = hex2bin(md5(substr($hash, 0, $keyLength))); |
|
60 | } |
|
61 | ||
62 | return substr($hash, 0, $keyLength); |
|
63 | } |
|
64 | ||
65 | return substr($hash, 0, 5); |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * Computes the owner entry as defined by algorithm 3.3 in 3.5.2. |