claimtoken
v0.0.1
Published
Claim Based Authentication Encryption via OpenSSL
Downloads
1
Readme
claimtoken-js
ClaimToken encrypts and signs tokens to be used in a claim-based authentication system. Will encrypt JSON providing a signature, IV and encrypted message({"data": "blah"}
). The returned objects IV and data is base64 encoded.
You can store the encrypted message in a cookie for use when authenticating with your other microservices.
Info about Claim Based Authentication
See our Ruby library for implementing in rails, sinatra etc.
Installation
Add this line to your application's Gemfile:
npm install claimtoken
Usage
claimtoken = require('claimtoken');
crypto = require('crypto');
ct = new ClaimToken();
// dont commit your keys into source control!
subject.configure(function(config) {
config.sharedEncryptionKey = crypto.randomBytes(32); // must be 32 bytes/char in length, change this to your own private key
config.digestSecret = crypto.randomBytes(81); // change this to your own secret digest
config.cypherType = "aes-256-cbc"; // optional and default
});
encrypted = ct.encrypt({foo: "bar"});
<!-- // returns
{
type: "EncryptedMessage",
cipher: "aes-256-cbc",
data: "P/2kgNhGBCu2WaF5lM3foW+tGdaJ3O/5tYSmhqg7rtI=",
iv: "CksPXjFY5oon22a4k2mjnQ==",
signature: "fa366a0a3ca6f4dfad954ff5b77eafc083f98c02"
}
-->
ct.decrypt(encryptedData);
<!-- // returns
Object#{foo: "bar"}
-->
Tests
npm test
mocha test --recursive --watch --debug