Leonid Nikitin
c3e4c68a41
Added a new CryptographyContract interface and CryptographyString class that implements this contract. The CryptographyContract encapsulates the encryption and decryption of strings, enforcing these operations to be standardized across the application. The CryptographyString class uses Laravel's native crypt facades to perform these actions. In the AppServiceProvider, CryptographyContract is now bound to CryptographyString class, allowing the container to automatically resolve the dependencies wherever the interface is type hinted.
20 lines
434 B
PHP
20 lines
434 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Contracts\CryptographyContract;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
final class CryptographyString implements CryptographyContract
|
|
{
|
|
public function encrypt(string $text): string
|
|
{
|
|
return Crypt::encryptString($text);
|
|
}
|
|
|
|
public function decrypt(string $encryptedText): string
|
|
{
|
|
return Crypt::decryptString($encryptedText);
|
|
}
|
|
}
|