A library for common encryption functions in Meshblu.
npm install --save meshblu-encryptionvar MeshbluEncryption = require('meshblu-encryption');
var meshbluEncryption = new MeshbluEncryption();
meshbluEncryption.register({}, function(error, response) {
// code goes here
})| Parameter | Type | Required | Description |
|---|---|---|---|
| nodeRsa | NodeRSA | yes | NodeRSA instance |
NodeRSA = require('node-rsa')
nodeRsa = new NodeRSA pem
var meshbluEncryption = new MeshbluEncryption({ nodeRsa })| Parameter | Type | Required | Description |
|---|---|---|---|
| pem | string | yes | text of a private key in pem format |
var meshbluEncryption = MeshbluEncryption.fromPem('--pem-data--')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--')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')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')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')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')