ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\PasswordHasher Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\PasswordHasher:

Static Public Member Functions

static hashPassword (string $password, string $algorithm='', string $salt='', int $spinCount=10000)
 Create a password hash from a given string by a specific algorithm. More...
 

Static Private Member Functions

static getAlgorithm (string $algorithmName)
 Get algorithm name for PHP. More...
 
static defaultHashPassword (string $pPassword)
 Create a password hash from a given string. More...
 

Detailed Description

Definition at line 8 of file PasswordHasher.php.

Member Function Documentation

◆ defaultHashPassword()

static PhpOffice\PhpSpreadsheet\Shared\PasswordHasher::defaultHashPassword ( string  $pPassword)
staticprivate

Create a password hash from a given string.

This method is based on the algorithm provided by Daniel Rentz of OpenOffice and the PEAR package Spreadsheet_Excel_Writer by Xavier Noguer xnogu.nosp@m.er@r.nosp@m.ezebr.nosp@m.a.co.nosp@m.m.

Parameters
string$pPasswordPassword to hash

Definition at line 49 of file PasswordHasher.php.

49 : string
50 {
51 $password = 0x0000;
52 $charPos = 1; // char position
53
54 // split the plain text password in its component characters
55 $chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
56 foreach ($chars as $char) {
57 $value = ord($char) << $charPos++; // shifted ASCII value
58 $rotated_bits = $value >> 15; // rotated bits beyond bit 15
59 $value &= 0x7fff; // first 15 bits
60 $password ^= ($value | $rotated_bits);
61 }
62
63 $password ^= strlen($pPassword);
64 $password ^= 0xCE4B;
65
66 return strtoupper(dechex($password));
67 }
$password
Definition: cron.php:14

References $password.

Referenced by PhpOffice\PhpSpreadsheet\Shared\PasswordHasher\hashPassword().

+ Here is the caller graph for this function:

◆ getAlgorithm()

static PhpOffice\PhpSpreadsheet\Shared\PasswordHasher::getAlgorithm ( string  $algorithmName)
staticprivate

Get algorithm name for PHP.

Definition at line 13 of file PasswordHasher.php.

13 : string
14 {
15 if (!$algorithmName) {
16 return '';
17 }
18
19 // Mapping between algorithm name in Excel and algorithm name in PHP
20 $mapping = [
31 ];
32
33 if (array_key_exists($algorithmName, $mapping)) {
34 return $mapping[$algorithmName];
35 }
36
37 throw new Exception('Unsupported password algorithm: ' . $algorithmName);
38 }

References PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_MD2, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_MD4, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_MD5, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_RIPEMD_128, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_RIPEMD_160, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_SHA_1, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_SHA_256, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_SHA_384, PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_SHA_512, and PhpOffice\PhpSpreadsheet\Worksheet\Protection\ALGORITHM_WHIRLPOOL.

Referenced by PhpOffice\PhpSpreadsheet\Shared\PasswordHasher\hashPassword().

+ Here is the caller graph for this function:

◆ hashPassword()

static PhpOffice\PhpSpreadsheet\Shared\PasswordHasher::hashPassword ( string  $password,
string  $algorithm = '',
string  $salt = '',
int  $spinCount = 10000 
)
static

Create a password hash from a given string by a specific algorithm.

2.4.2.4 ISO Write Protection Method

See also
https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-offcrypto/1357ea58-646e-4483-92ef-95d718079d6f
Parameters
string$passwordPassword to hash
string$algorithmHash algorithm used to compute the password hash value
string$saltPseudorandom string
int$spinCountNumber of times to iterate on a hash of a password
Returns
string Hashed password

Definition at line 83 of file PasswordHasher.php.

83 : string
84 {
85 $phpAlgorithm = self::getAlgorithm($algorithm);
86 if (!$phpAlgorithm) {
88 }
89
90 $saltValue = base64_decode($salt);
91 $encodedPassword = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
92
93 $hashValue = hash($phpAlgorithm, $saltValue . $encodedPassword, true);
94 for ($i = 0; $i < $spinCount; ++$i) {
95 $hashValue = hash($phpAlgorithm, $hashValue . pack('L', $i), true);
96 }
97
98 return base64_encode($hashValue);
99 }
static defaultHashPassword(string $pPassword)
Create a password hash from a given string.
static getAlgorithm(string $algorithmName)
Get algorithm name for PHP.
$i
Definition: disco.tpl.php:19
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406

References $i, $password, PhpOffice\PhpSpreadsheet\Shared\PasswordHasher\defaultHashPassword(), PhpOffice\PhpSpreadsheet\Shared\PasswordHasher\getAlgorithm(), and GuzzleHttp\Psr7\hash().

Referenced by PhpOffice\PhpSpreadsheet\Worksheet\Protection\setPassword(), PhpOffice\PhpSpreadsheet\Document\Security\setRevisionsPassword(), PhpOffice\PhpSpreadsheet\Document\Security\setWorkbookPassword(), and PhpOffice\PhpSpreadsheet\Worksheet\Protection\verify().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: