jtd420/laravel-pgp

Automatic PGP Encryption/Decryption for your laravel application. Fully customisable and works out-the-box with the default provided scaffolding!

dev-main 2023-02-16 01:40 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Important Notice

Please be advised that Laravel-PGP is currently in its early stages of development (version 0.0.1) and may not be suitable for production use in critical environments.

This package provides a convenient way for Laravel users to add PGP encryption and decryption functionality to their projects, with the added bonus of default scaffolding for a chat interface.

However, as with any new software, it is still undergoing testing and refinement. We recommend that users exercise caution and carefully evaluate its suitability for their specific use case before implementing it in a live environment.

Support us

Future updates will include ways to support this project and others.

68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f392f39612f4c61726176656c2e7376672f3132303070782d4c61726176656c2e7376672e706e67

Installation

You can require the package via composer:

composer require jtd420/laravel-pgp

Installing the package

To install the package into your Laravel application, you need to require it using composer and run the following Artisan command:

php artisan PGP::install blade

If you prefer a dark theme, the following command can be run instead with the --dark option:

php artisan PGP::install blade --dark

You can publish and run the migrations with:

php artisan vendor:publish --tag="PGP-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="PGP-config"

This is the contents of the published config file:

return [
    /*
     * To prevent naming conflicts, this prefix will be added to all Laravel-PGP migrations.
     */
    'table_prefix' => 'pgp_',

    /*
     * Prefix added to rest of Laravel-PGP code, including routes. (Delete default to remove prefix)
     */
    'prefix' => 'PGP',

    /*
     * Choose the layout file to be extended by the views provided in the package.
     * The default layout file is set to 'PGP::layouts.app', but can be changed to match your preferred layout.
     */
    'layout_file' => 'PGP::layouts.app',
    /*
     * Choose the section name to be used in the views provided in the package.
     * The default section name is set to 'content', but it can be changed to match the section defined in your custom layout file.
     * This option is only applicable if you have set a custom 'layout_file' with a different '@section()' name.
     */

    'layout_section' => 'content',


    'uses_custom_auth' => true,

];

Optionally, you can publish the views using

php artisan vendor:publish --tag="PGP-views"

Usage

This package includes the PGPController class located at App/Http/Controllers/PGPController for users who want to understand the inner workings of the package and possibly modify it. However, if all you want is the default encrypted messaging functionality, there's no need for any additional setup. The package provides sensible defaults for easy use, as well as being highly customizable for those who want to extend it.

To use the class and its methods, it must be imported into a controller and instantiated:

use App\Http\Controllers\PGPController;
$controller = new PGPController();

Generating a Keypair

The generate_keypair method generates a public/private keypair and returns both the public and private key as enarmoured PGP keys.

$keypair = $controller->generate_keypair('Name', 'email@email.com', 'RealSecurePassPhrase');
$public_key = $keypair['public_key'];
$private_key = $keypair['private_key'];

Encrypting a Message

The encrypt method takes a public key and a message and returns an encrypted enarmoured PGP message.

$encrypted_message = $controller->encrypt($public_key, 'secret message');

Decrypting a Message

The decrypt method takes a private key, encrypted message and passphrase and returns either the decrypted message or a json error if decryption fails.

$decrypted_message = $controller->decrypt($private_key, $encrypted_message, 'RealSecurePassPhrase');

For more, see the wiki here!

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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