smakecloud/laravel-sodium

v0.0.2 2023-06-21 12:35 UTC

This package is not auto-updated.

Last update: 2024-11-07 16:47:14 UTC


README

phpunit phpstan

Uses PHP's Sodium extension to encrypt, decrypt, sign and verify data.

Note Package name was chosen for discoverability. It is not affiliated with Laravel.

Supported encryption ciphers are:

Supported signing algorithms are:

Signing KeyPair is generated using app.key for seeding.

Warning This package overrides Laravel's Encrypter class!

You will lose support for the following ciphers:

  • AES-128-CBC
  • AES-256-CBC
  • AES-128-GCM

Table of Contents

Requirements

  • PHP 8.1+
  • Sodium extension ( obviously )

Installation

You can install the package via composer:

composer require smakecloud/laravel-sodium

This package uses Laravel's auto-discovery feature. After you install it the package provider and facade are available immediately.

Usage

This package overrides Laravel's Encrypter class. You can use it as you would use the default Encrypter class.

You can change the default cipher in:

config/app.php

return [
    //...

    'cipher' => 'XCha-Cha20-Poly1305',

    //...
]
$encrypted = encrypt('secret');
$decrypted = decrypt($encrypted); // 'secret'

$signed = sign('secret');
$verified = verify($signed); // 'secret'

$signature = sign_detached('secret');
$verified = verify_detached($signature, 'secret'); // true

Development

Testing

composer test

Coverage

composer test:coverage

Static analysis

composer phpstan

Code style

composer lint(:fix)

Disclaimer

This package is not affiliated with Laravel in any way.

Read the documentation of PHPs sodium extension before using this package !

We don't take any responsibility for any damage caused by this package.

License

The MIT License (MIT). Please see License File for more information.