Coder Social home page Coder Social logo

php-license's Introduction

php-license is a library for generating and parsing license
PHP License

Codecov Build Status

php-license is a library for generating and parsing license.

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 ziishaned/php-license

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 Ziishaned\PhpLicense\PhpLicense;

$data = [
  "firstName" => "John",
  "lastName"  => "Doe",
  "email"     => "[email protected]",
];

$privateKey = file_get_contents('path/to/private_key.pem');
$license    = PhpLicense::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 Ziishaned\PhpLicense\PhpLicense;

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

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

var_dump($parsedLicense);

The above code will output the following result:

{
    "firstName": "John",
    "lastName": "Doe",
    "email": "[email protected]"
}

Contributions

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

License

MIT © Zeeshan Ahmad

php-license's People

Contributors

owenvoke avatar samnela avatar ziishaned avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

php-license's Issues

Typo in error text

php-license/src/PhpLicense.php, "OpenSSL: Enable to generate signature" should probably be "OpenSSL: Unable to generate signature".

Requirements should be checked

The requirements should be checked in the code; what will happen if PHP version is lower that 5.6, does the application fail gracefully? But if OpenSSL is missing or not properly working?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.