tricioandrade/openscrypt

A package for data encryption

v2.0.1 2023-09-09 21:58 UTC

This package is auto-updated.

Last update: 2024-11-11 13:35:48 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

OpensCrypt is a package that aims to integrate scripts Classes or Objects, methods that will use PHP's cryptographic functions to encrypt data.

The class uses the Openssl php library to generate key pairs for asymmetric encryption.

Installation

composer require tricioandrade/openscrypt

How to use generate keys

<?php
    $instance = new GenerateKeys();
    $instance->generate();
    
    // Print or save your keys anywere 
    $instance->getKeys();

Change where you want save your keys

    $instance = new GenerateKeys(__DIR__ . '\\');

Get complete keys path or the generated keys:

    $instance = new GenerateKeys(__DIR__ . '\\');
    $instance->generate();
    
    if ($instance->isPem()){
        print_r($instance->getKeysPath());
    }
    else{
        print_r($instance->getKeys());
    }

Change files name:

    $instance->privateKeyFileName   = 'MyPrivateKey.pem';
    $instance->publicKeyFileName    = 'MyPublicKey.pem';

Starting encryption

    $cypher = new Cypher('Hello');
        
    print_r(
        $cypher->setCypherKey(file_get_contents('./MyPrivateKey.pem'))
        ->getHash()
    );