From a2d296308dcaf06832e43cedc584429212690645 Mon Sep 17 00:00:00 2001 From: andkom Date: Sun, 16 Oct 2022 14:58:05 +0300 Subject: [PATCH] optional encrypted key --- Dockerfile | 10 +++++----- src/Item/MasterKey.php | 9 ++++----- tests/WalletTest.php | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 51c75e0..5072159 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ -FROM php:7.2-cli +FROM php:7.4-cli RUN apt-get update && apt-get install -y libdb5.3++-dev -RUN curl -O --referer https://fossies.org/linux/misc/db-18.1.25.tar.gz/ \ - https://fossies.org/linux/misc/db-18.1.25.tar.gz \ - && tar -zxf db-18.1.25.tar.gz && cd db-18.1.25/lang/php_db4/ \ +RUN curl -O --referer https://fossies.org/linux/misc/db-18.1.40.tar.gz/ \ + https://fossies.org/linux/misc/db-18.1.40.tar.gz \ + && tar -zxf db-18.1.40.tar.gz && cd db-18.1.40/lang/php_db4/ \ && phpize \ && ./configure --with-db4 \ && make \ && make install \ && docker-php-ext-enable db4 -RUN apt-get install libgmp-dev \ +RUN apt-get install -y libgmp-dev \ && docker-php-ext-install gmp \ No newline at end of file diff --git a/src/Item/MasterKey.php b/src/Item/MasterKey.php index 33ac496..27d4f57 100644 --- a/src/Item/MasterKey.php +++ b/src/Item/MasterKey.php @@ -68,14 +68,13 @@ public function getDerivationIterations(): int /** * Returns master key hash for hashcat. - * @param EncryptedKey $encryptedKey + * @param EncryptedKey|null $encryptedKey * @return string - * @throws \AndKom\Bitcoin\Wallet\Exception */ - public function getHash(EncryptedKey $encryptedKey): string + public function getHash(EncryptedKey $encryptedKey = null): string { - $encrypted = bin2hex($encryptedKey->getEncryptedPrivateKey()); - $public = bin2hex($encryptedKey->getPublicKey()); + $encrypted = $encryptedKey ? bin2hex($encryptedKey->getEncryptedPrivateKey()) : '00'; + $public = $encryptedKey ? bin2hex($encryptedKey->getPublicKey()) : '00'; $master = substr(bin2hex($this->getEncryptedKey()), -64); // last two aes blocks should be enough $salt = bin2hex($this->getSalt()); diff --git a/tests/WalletTest.php b/tests/WalletTest.php index 4824c91..71598c7 100644 --- a/tests/WalletTest.php +++ b/tests/WalletTest.php @@ -36,6 +36,7 @@ public function testMasterKey() $this->assertEquals($mk->getDerivationMethod(), 0); $this->assertEquals($mk->getDerivationIterations(), 196349); $this->assertEquals($mk->getHash($key), '$bitcoin$64$681a195c345695c6e87396eb7f8aefbf4e098ed009a42a173bd6db863c24d464$16$98313fb978e6ef49$196349$96$efe4244d839af470418ee08b278ffd20510dcd105bd1aa3de016bf59c35f99b8537222a0e4a8ea1db2b6b795de697785$66$03f4c3e512b84d950cf7568966a89c9048526076a2654c907a43db8fb8f38db508'); + $this->assertEquals($mk->getHash(), '$bitcoin$64$681a195c345695c6e87396eb7f8aefbf4e098ed009a42a173bd6db863c24d464$16$98313fb978e6ef49$196349$2$00$2$00'); } public function testDecrypt()