Skip to content

octoblu/meshblu-encryption

Repository files navigation

meshblu-encryption

A library for common encryption functions in Meshblu.

Build Status Code Climate Test Coverage npm version Gitter

Usage

Install:

npm install --save meshblu-encryption

Use:

var MeshbluEncryption = require('meshblu-encryption');

var meshbluEncryption = new MeshbluEncryption();

meshbluEncryption.register({}, function(error, response) {
  // code goes here
})

Functions

Constructor

Parameter Type Required Description
nodeRsa NodeRSA yes NodeRSA instance

NodeRSA = require('node-rsa')
nodeRsa = new NodeRSA pem
var meshbluEncryption = new MeshbluEncryption({ nodeRsa })

fromPem

Parameter Type Required Description
pem string yes text of a private key in pem format

var meshbluEncryption = MeshbluEncryption.fromPem('--pem-data--')

fromJustGuess

Will try to guess the format of the provided string and convert it to a nodeRSA object.

Parameter Type Required Description
thing string yes text of a private key in some format

var meshbluEncryption = MeshbluEncryption.fromJustGuess('--pem-data--')

decrypt

Will decrypt the given data and return the unencrypted value, expects stringified JSON in base64.

Parameter Type Required Description
data string yes the string to decrypt

var decryptedData = meshbluEncryption.decrypt('encrypted-string')

encrypt

Will convert the given data to a JSON string, encrypt, and return a base64 encoded encrypted string

Parameter Type Required Description
data string yes the string to encrypt

var encryptedData = meshbluEncryption.encrypt('string')

sign

Will convert the given data to a JSON string, and return a signature for that data

Parameter Type Required Description
data string yes the string to sign

var signature = meshbluEncryption.sign('string')

verify

Will verify a signature for the given data

Parameter Type Required Description
data string yes the string to verify
signature string yes the signature to verify

var isValid = meshbluEncryption.verify('encrypted-string', 'signature')