nihilsen/keypad

Client-side cryptography framework for Laravel using Blade components and native Web Crypto API.

v0.4.0 2023-04-07 04:21 UTC

README

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

Keypad is a Laravel package that aims to make it easier to add client-side encryption and decryption to your Laravel applications.

Keypad offers a suite of reactive Blade components that can be inserted into your existing authentication forms.

Under the hood, Keypad uses browser-native Web Crypto API.

Installation

You can install the package via composer:

composer require nihilsen/keypad

You can run the migrations with:

php artisan migrate

You can publish the config file with:

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

This is the contents of the published config file:

https://github.com/nihilsen/keypad/blob/14e862c555354edbf36fa851c09a167114930a98/config/keypad.php#L3-L23

Components and usage

Login: <x-keypad::login>

<form method="POST" action="/login/">
    {{ -- CSRF token -- }}
    @csrf
    
    {{ -- email field -- }}
    <input type="email" name="email_field" placeholder="email" />
    
    {{ -- password field -- }}
    <input type="password" name="password_field" placeholder="password" />
    
    {{ -- Keypad "login" component -- }}
    <x-keypad::login password="password_field" />
    
    {{ -- other form elements, submit button, etc ... -- }}
</form>

Register: <x-keypad::register>

<form method="POST" action="/register/">
    {{ -- CSRF token -- }}
    @csrf
    
    {{ -- email field -- }}
    <input type="email" name="email_field" placeholder="email" />
    
    {{ -- password field -- }}
    <input type="password" name="password_field" placeholder="password" />
    
    {{ -- confirm password field -- }}
    <input type="password" name="confirm_password_field" placeholder="confirm password" />
    
    {{ -- Keypad "register" component -- }}
    <x-keypad::register password="password_field" confirmation="confirm_password_field" />
    
    {{ -- other form elements, submit button, etc ... -- }}
</form>

Encrypt: <x-keypad::encrypt>

<form method="POST" action="/send_message/">
    {{ -- CSRF token -- }}
    @csrf
    
    {{ -- plaintext message field -- }}
    <input type="text" name="secret_message" placeholder="Enter your message" />
    
    {{ -- get recipient keypad -- }}
    @php
        $recipient = User::find($__GET['recipient_id']);
        $keypad = $recipient->keypad;
    @endphp
    
    {{ -- Keypad "encrypt" component -- }}
    <x-keypad::encrypt target="secret_message" :$keypad />
    
    {{ -- other form elements, submit button, etc ... -- }}
</form>

Decrypt: <x-keypad::decrypt>

<x-keypad::decrypt>{{ $message->secret_message }}</x-keypad::decrypt>

Changelog

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

Roadmap

  • <x-keypad::login />
  • <x-keypad::register />
  • <x-keypad::encrypt />
  • <x-keypad::decrypt />
  • <x-keypad::hash />
  • <x-keypad::change-password />
  • <x-keypad::recover />

Contributing

  • Pull requests, bug reports and feature requests are welcome.

Credits

License

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