Giter VIP home page Giter VIP logo

nodejs-license-file's Introduction

nodejs-license-file Build Status

A lightweight License file generator and parser for NodeJS.

Generate a keypair using OpenSSL

  1. Generate an RSA 2048 bit private key

    openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048

  2. Extract the public key from an RSA keypair

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

Generating license file

const licenseFile = require('nodejs-license-file');

const template = [
    '====BEGIN LICENSE====',
    '{{&licenseVersion}}',
    '{{&applicationVersion}}',
    '{{&firstName}}',
    '{{&lastName}}',
    '{{&email}}',
    '{{&expirationDate}}',
    '{{&serial}}',
    '=====END LICENSE====='
].join('\n');

try {
 
    const licenseFileContent = licenseFile.generate({
        privateKeyPath: 'path/to/key.pem',
        template,
        data: {
            licenseVersion: '1',
            applicationVersion: '1.0.0',
            firstName: 'Name',
            lastName: 'Last Name',
            email: '[email protected]',
            expirationDate: '12/10/2025'
        }
    });
    
    console.log(licenseFileContent);

} catch (err) {
    
    console.log(err);
}

This will produce a license key, which uses the default template and will look similar to this:

====BEGIN LICENSE====
1
1.0.0
Name
Last Name
[email protected]
12/10/2025
xxxxxxxxxxxxxxxxxxxxx
=====END LICENSE=====

Parse and verify license file

const licenseFile = require('nodejs-license-file');

try {
 
    const data = licenseFile.parse({
        publicKeyPath: 'path/to/key.pub',
        licenseFilePath: 'path/to/file.lic',
        template
    });
    
    console.log(data);
    
} catch (err) {
    
    console.log(err);
}

There is an execution result:

{
    valid: true,
    serial: 'oZDqoEr2avwhAqwV4HInq9otNzeBeD/azq2yn2jA ...',
    data: {
        licenseVersion: '1',
        applicationVersion: '1.0.0',
        firstName: 'Name',
        lastName: 'Last Name',
        email: '[email protected]',
        expirationDate: '12/10/2025'
    }
}

NOTICE: All numeric data will be converted to strings after parsing. You need to take care of a parsed data types.

Parse and verify license string

const licenseFile = require('nodejs-license-file');

try {

    const licence = `
====BEGIN LICENSE====
1
1.0.0
Name
Last Name
[email protected]
12/10/2025
xxxxxxxxxxxxxxxxxxxxx
=====END LICENSE=====
    `;
 
    const data = licenseFile.parse({
        publicKeyPath: 'path/to/key.pub',
        licenseFile: licence,
        template
    });
    
    console.log(data);
    
} catch (err) {
    
    console.log(err);
}

There is an execution result:

{
    valid: true,
    serial: 'oZDqoEr2avwhAqwV4HInq9otNzeBeD/azq2yn2jA ...',
    data: {
        licenseVersion: '1',
        applicationVersion: '1.0.0',
        firstName: 'Name',
        lastName: 'Last Name',
        email: '[email protected]',
        expirationDate: '12/10/2025'
    }
}

NOTICE: All numeric data will be converted to strings after parsing. You need to take care of a parsed data types.

nodejs-license-file's People

Contributors

bushev avatar r3nya avatar rjgreavesfp avatar

Watchers

 avatar

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.