PHP library for generating and parsing data

1.9.7 2023-02-02 19:08 UTC

This package is auto-updated.

Last update: 2024-03-30 00:19:02 UTC


README

68747470733a2f2f636f6465636f762e696f2f67682f696e67726573732d69742d736f6c7574696f6e732f67656e657261746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f747769747465722d74776565742d626c75652e7376673f7374796c653d666c61742d737175617265

generator is a library for generating and parsing data.

Requirements

  • PHP >= 5.4
  • OpenSSL

Generating Key Pair

Make sure OpenSSL is configured on your machine.

  1. Generate the Private key file by running the following command:

    openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
  2. Run the following command to generate public key:

    openssl rsa -pubout -in private_key.pem -out public_key.pem

Installation

composer require ingress-it-solutions/generator

Usage

Before running the following code make sure you have the public_key and private_key files.

Generating

Use the following code to generate the license key:

<?php

use IngressITSolutions\Generator\Generator;

$data = [
  "firstName" => "John",
  "lastName"  => "Doe",
  "email"     => "john_doe@email.com",
];

$privateKey = file_get_contents('path/to/private_key.pem');
$license    = Generator::generate($data, $privateKey);

var_dump($license);

The above code will output the following result:

agW4Riht6xHEfbpDaZUcTCmZVHgGgCnzXc0+nqLAMjuS6ouuGQVv/JqjAuo89tUgTu3F7Q+WProPcNm1aXdavxj3xOxTJ3e2w0NSS09sBZONxG9MzzofqvYPCnu/I1WMLgaRXiiNJcz5WtqFLFSdTgehqU5VLO+eDhfWUeZ0EJlCtCLPu19hP56/+24+/tmnh4ySLc9tV+YGLYtpmt7Gyf+h3sbMO0SJMwe+XSuuTcUsIUDg3AQUlj7c4ctwhkdYkRyyjj27U09CgpWWgU5b3sXSqZ3DFdTNaP8sIVH3Y39b7/o+Gx7WIHzngCnczK58L81LTVwnkyzSBqKUT5oq4A==

Parsing

Use the following code to parse the license key:

<?php

use IngressITSolutions\Generator\Generator;

$license = 'agW4Riht6xHEfbpDaZUcTCmZVHgGgCnzXc0+nqLAMjuS6ouuGQVv/JqjAuo89tUgTu3F7Q+WProPcNm1aXdavxj3xOxTJ3e2w0NSS09sBZONxG9MzzofqvYPCnu/I1WMLgaRXiiNJcz5WtqFLFSdTgehqU5VLO+eDhfWUeZ0EJlCtCLPu19hP56/+24+/tmnh4ySLc9tV+YGLYtpmt7Gyf+h3sbMO0SJMwe+XSuuTcUsIUDg3AQUlj7c4ctwhkdYkRyyjj27U09CgpWWgU5b3sXSqZ3DFdTNaP8sIVH3Y39b7/o+Gx7WIHzngCnczK58L81LTVwnkyzSBqKUT5oq4A==';

$publicKey     = file_get_contents('path/to/public_key.pem');
$parsedLicense = Generator::parse($license, $publicKey);

var_dump($parsedLicense);

The above code will output the following result:

{
    "firstName": "John",
    "lastName": "Doe",
    "email": "john_doe@email.com"
}

Contributions

Feel free to submit pull requests, create issues or spread the word.

License

MIT © Ingress IT Solutions