feat: encrypted user passwords
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security;
|
||||
|
||||
use Spatie\Crypto\Rsa\PrivateKey;
|
||||
use Spatie\Crypto\Rsa\PublicKey;
|
||||
|
||||
class Crypt
|
||||
{
|
||||
public function __construct(private readonly string $path)
|
||||
{
|
||||
}
|
||||
|
||||
public function encrypt(string $message): string
|
||||
{
|
||||
$privateKey = PrivateKey::fromFile($this->path . '/private.key');
|
||||
|
||||
return $privateKey->encrypt($message);
|
||||
}
|
||||
|
||||
public function decrypt(string $message): string
|
||||
{
|
||||
$publicKey = PublicKey::fromFile($this->path . '/public.key');
|
||||
|
||||
return $publicKey->decrypt($message);
|
||||
}
|
||||
|
||||
public function sign(string $message): string
|
||||
{
|
||||
$privateKey = PrivateKey::fromFile($this->path . '/private.key');
|
||||
|
||||
return $privateKey->sign($message);
|
||||
}
|
||||
|
||||
public function verify(string $message, string $signature): bool
|
||||
{
|
||||
$publicKey = PublicKey::fromFile($this->path . '/public.key');
|
||||
|
||||
return $publicKey->verify($message, $signature);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user