Skip to content

Commit

Permalink
Change bin2hex for ParagonIE\ConstantTime\Hex::encode
Browse files Browse the repository at this point in the history
Signed-off-by: Pitos <[email protected]>
  • Loading branch information
gawsoftpl committed Aug 19, 2023
1 parent c3fc116 commit cb0fa5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Commands/GenerateKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Console\Attribute\AsCommand;
use ParagonIE\ConstantTime\{
Base64UrlSafe,
Hex
};

#[AsCommand(name: 'ciphersweet:generate-key')]
Expand Down Expand Up @@ -65,8 +66,7 @@ protected function generateRandomKey(): string
$randomBytes = $this->generateRandomBytes();
if ($this->option('base64'))
return Base64UrlSafe::encode($randomBytes);

return bin2hex($randomBytes);
return Hex::encode($randomBytes);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/CipherSweetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Spatie\LaravelCipherSweet\Commands\EncryptCommand;
use Spatie\LaravelCipherSweet\Tests\TestClasses\User;
use Spatie\LaravelCipherSweet\Commands\GenerateKeyCommand;

beforeEach(function () {
$this->user = User::create([
Expand Down Expand Up @@ -116,6 +115,11 @@
User::first(); // Shouldn't throw an exception.
});

it('can generate key in hex', function(){
$this->artisan('ciphersweet:generate-key --show')
->assertSuccessful();
});

it('can generate key in base64', function(){
$this->artisan('ciphersweet:generate-key --show --base64')
->assertSuccessful();
Expand Down

0 comments on commit cb0fa5c

Please sign in to comment.