Coder Social home page Coder Social logo

leeyeung1314 / secure-tokens Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sarxos/secure-tokens

0.0 1.0 0.0 160 KB

Small set of tools allowing you to create secure encrypted tokens, which can be later exchanged with 3rd party systems or stored as a license files. The goal of this project is to play with JCA and learn its API.

License: MIT License

Java 100.00%

secure-tokens's Introduction

Secure Tokens

Secure Tokens is a set of tools / classes / annotations allowing you to create secure encrypted tokens from any object, which can be later exchanged with 3 rd party systems or simply stored as license file.

Features

  1. Supports following ciphers:
    • AES
    • Blowfish
    • Camelia
    • DES
    • IDEA
    • Noekeon
    • NOOP (no-operation)
    • SEED
    • Serpent
    • Twofish
  2. Supports compression (long tokens are GZIP-compressed)
  3. Support machine Serial Number identification

Example

Below there are some secret information in Example class. We would like to encrypt them and send to some 3 rd party system along with some kind of request identification โ€“ in this case this will be computer serial number obtained from Hardware class.

Assume we have the following class:

public static class Example implements Token {
	/**
	 * Some kind of secret data.
	 */
	@TokenPart("id")
	protected int id = 4;
	/**
	 * Some other kind of secret data 2.
	 */
	@TokenPart("sec")
	protected String secret = "secret.information.is.here";
	/**
	 * Computer Serial Number
	 */
	@TokenPart("sn")
	protected String sn = Hardware.getSerialNumber();
}

And the main method:

public static void main(String[] args) {
	Example example = new Example();
	CipherType cipher = CipherType.AES;
	String password = "secret password";
	String token = Tokenizer.tokenize(example, cipher, password);
	System.out.println("token:  " + token);
	Example checkme = Tokenizer.objectify(Example.class, token, cipher, password);
	System.out.println("id:     " + checkme.id);
	System.out.println("secret: " + checkme.secret);
	System.out.println("sn:     " + checkme.sn);
}

The output will be:

token:  9bLvGViEM7zAG872nz9W3wHGIFfl0j14lfNoogwCkZn0i7bbOhz3xukYopBKxjAXR75ht/DeF29wxuFMO3kFQQ==
id:     4
secret: secret.information.is.here
sn:     CZC14057LY

Of course there is a possibility to not encrypt data if someone would like to create clear text token. This can be done by using CipherType.NOOP (no-operation) cipher:

public static void main(String[] args) {
	Example example = new Example();
	CipherType cipher = CipherType.NOOP;
	String password = "secret password";
	String token = Tokenizer.tokenize(example, cipher, password);
	System.out.println("token:  " + token);
}

This will print:

token:  id=4#sn=CZC14057LY#sec=secret.information.is.here

secure-tokens's People

Contributors

sarxos avatar kulmann avatar

Watchers

James Cloos 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.