diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e3019..7ec4f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,4 +30,8 @@ * Fix for very slow encryption [#10](https://github.com/nick322/secure-spreadsheet/issues/10) . - Thanks for @jonathanbromley contribution. \ No newline at end of file + Thanks for @jonathanbromley contribution. + +## 1.0.9 (2023-09-20) + +* Fix password is not accepted [#18](https://github.com/nick322/secure-spreadsheet/issues/18) diff --git a/src/Encrypt.php b/src/Encrypt.php index bc2cd37..6b14518 100644 --- a/src/Encrypt.php +++ b/src/Encrypt.php @@ -358,7 +358,16 @@ private function _crypt($encrypt, $cipherAlgorithm, $cipherChaining, $key, $iv, private function _hash($algorithm, ...$buffers) { - return unpack('C*', hash(strtolower($algorithm), pack('C*', ...$buffers), true)); + $algorithm = strtolower($algorithm); + + $buffers = array_merge([], ...$buffers); + + if (!in_array($algorithm, hash_algos())) throw new \Exception("Hash algorithm '$algorithm' not supported!"); + + $ctx = hash_init($algorithm); + + hash_update($ctx, pack('C*', ...$buffers)); + return unpack('C*', hash_final($ctx, true)); } private function _hmac($algorithm, $key, $fileName)