Coder Social home page Coder Social logo

clavis's Introduction

Clavis

Clavis is a framework for easily generating and validating software licenses for your app.

How to license your app

To use Clavis for license managing, you need to follow these steps:

  • Generate RSA key pair (once)
  • In a seperate application/command line tool/server app: Generate licenses with Clavis for your users using the private key
  • In your app: Validate licenses using Clavis at app startup using the public key. The public key needs to be shipped with the app.

Important: Don't share your private key, this is the one you keep. Also make sure you don't loose it otherwise you will need to update your app with a new public key, in order to issue new licenses.

Read more on licensing an application here.

Usage

Generate RSA Keys

To use Clavis, you need a public an a private RSA Key. You can generate them using the openssl command line utility.

Generate private key using

openssl genrsa -out private.pem 2048

Generate public key using

openssl rsa -in private.pem -outform PEM -pubout -out public.pem

Generate Licenses

To generate a license, you will need the private key and a message, which will be encrypted in the license. This can be the name or the email or a combination of both of the person, for whom the license was issued. The license can be limited by specifying an expiration date. If no expiration date is specified, then the license is unlimited.

// Unlimited license
let plaintext = "John Doe"
let license = try Clavis.Generator.license(privateKey: privateKey, publicKey: publicKey, keyMessage: plaintext)

// Limited license
let todayPlusOneDay = Date().addingTimeInterval(24*3600.0)
let licenseLimited = try Clavis.Generator.license(privateKey: privateKey, publicKey: publicKey, keyMessage: plaintext, expirationDate: todayPlusOneDay)

Validate Licenses

To validate a license, you need to provide the public key, the license and the message. The isValid method will then check, if the given license is equal to the given plaintext and thus valid.

let license = "zHFGj6rhT9Kxb5..."
let plaintext = "John Doe"
let validation = try Clavis.Validator.isValid(license: license, plaintext: plaintext, publicKey: publicKey)

In order to have a better user experience, isValid will store the license in the keychain, so that the user doesn't have to type it in at every app startup. Use hasValidLicense to check, if there is a valid license stored in the keychain.

if try Clavis.Validator.hasValidLicense(publicKey: publicKey) {
    // Start app
} else {
    // Ask for license
}

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.