1.0.4 • Public • Published

DataShield AI

DataShield AI: Real-time Automated AI Enhanced Policy Based Encryption


This is the official node-js port of Datashield.AI SDK. This SDK is used to encrypt and decrypt data using the ECSMID API. The SDK is available for the following languages:


npm install @lokdon/datashield


Visit ( to get your license keys.

Initializing the library

Import the DataShield class from the package and initialize it with the configuration. The configuration object contains the following properties:

const { DataShield } = require('@lokdon/datashield');
const dataShield = new DataShield({
    connection: {
        client: '<db_driver eg. mysql>',
        connection: {
            host: '<db-server eg. localhost>',
            user: '<db-user eg. root>',
            password: '<db-pass>',
            database: '<schema-name>'
    token: "<Your API Key>"

Creating a table (for SQL based databases)

DataShield uses knex.js package to build sql queries internally. If your project is already based on knex.js, integration can be done with minimal refactoring

await dataShield.query().schema.createTable('users', (table) => {

Inserting data/rows to sql table

To insert a data to a sql table using datashield, you need to pass the TABLE_NAME, ROW_DATA and ENCRYPTED_COLUMNS_LIST to the insert method the format is dataShield.insert(TABLE_NAME, DATA_ARRAY, COLUMNS_TO_ENCRYPT); the default value for COLUMNS_TO_ENCRYPT is [], which means all columns will be saved as plain text.

// populate the data in a associative array
// the keys will be used as column names and the values are the data to be inserted
    const sampleData = [
    {  name: 'Alice', email: '', age: 25 },
    {  name: 'Bob', email: '', age: 30 },
    {  name: 'Charlie', email: '', age: 35 }
// specify which columns should be encrypted
const columnsToEncrypt=['name','email'];
// iterate through the data array and insert each row using datashield
// datashield automatically encrypts and stores the data with the appropriate character encoding
for (const data of sampleData) {
    await dataShield.insert('users', data, columnsToEncrypt);

Retrieving data/rows from sql table

To retrieve rows from sql table datashield builds a select query with the arguments you specify and decrypts the previously encrypted columns For example, the following code snippet generates a select query which returns the rows including those encrypted now decrypted.

            .then((data) => => {
                console.log('####> Retrieved row', row);
                return {
                    age: row.age
            })).catch((err) => {
                console.log('####> Error', err);

Performing DDL queries

Performing DDL using datashield is straightforward

// drops the users table from the schema

// drops the schema in use

Using DataShield with nosql databases

Instructions for MongoDB

DataShield uses mongoose to connect to MongoDB and perform schema related operations.

  1. To get started, simply install the datashield node package
npm install @lokdonllc/datashield
  1. import the DatashieldMongoose module into your node script.
const DatashieldMongoose=require('DataShieldMongoose');
  1. Initialize Datashield with your API token
const ds=new DatashieldMongoose(<YOUR_API_TOKEN>);
  1. Connect to your MongoDB instance using mongoose & datshield
ds.mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});

You can use this ds.mongoose instance exactly as the mongoose library.

Creating encrypted schemas

Datashield provides encrypted schema types for mongoose. The following encrypted schema types have been tested well and available for production use in this release of datashield

  • EncryptedString: This type supports encryption & decryption of any string type including JS objects that implement toString
  • EncryptedNumber: This type supports encryption & decryption of number & bigint values. Note that it always returns a number type once decrypted
  • EncryptedArray: This type encrypts & decrypts javascript arrays. It currently only supports String Arrays with one dimension. e.g. ['apples','oranges', 'bananas']

For example, let's create a schema which demonstrates the use of all the above schema types:

// complete steps 1 - 4 above, so you have ds.mongoose instance
// let's create a schema for Travellers:
// specify the fields we want to encrypt based on their types
// make sure to avoid encrypting indexed values or properties which we later use for searching the object
// in this case email is a property we want to use later for searching
const travellersSchema = new ds.mongoose.Schema({
    first_name: ds.EncryptedString,
    last_name: ds.EncryptedString,
    email: String,
    gender: ds.EncryptedString,
    tickets: ds.EncryptedArray,
    age: ds.EncryptedNumber

// register the schema created above with mongoose
const travellerModel = ds.mongoose.model('travellers',travellersSchema);

// populate or prepare the traveller objects you want to save to db
const travellersList=

// iterate over each traveller from the list and save it to db
// datashield automatically encrypts the values before saving it to db based on the types you specify
for(let i=0;i<travellersList.length;i++){
    new travellerModel(travellersList[i]).save()

// To retreive the objects from the database you can use the mongoose provided functions
// upon retreival, datashield automatically decrypts the values before returned in the promise
        for(let i=0;i<result.length;i++){
            let travellerFromDB=result[i];
            let traveller=travellersList[i];
        console.log('all '+result.length+' tests passed');

Using datashield with other schema types

** If you intend to encrypt a different data type than the above, you can easly do that by converting the object you are encrypting to a json string before encrypting & parsing the json string after decrypted** example:

// consider this is the object you want to encrypt using datasheild
let person={
// convert the personObject to string before encryption
const personToString=JSON.stringify(person);

// specify to use EncryptedString type for person in your schema
const userSchema = new ds.mongoose.Schema({
    person: ds.EncryptedString,
    username: String,
    password: ds.EncryptedString

//create the user model
const userModel = ds.mongoose.model('User',userSchema);

// create the user object
const userObj= new userModel({
    person: personToString,
    username: 'user1',
    password: '12345678'

// save the object to database
// datashield automatically encrypts the person & password fields before saving it to database;

// fetch the user data
userModel.findOne({username: 'user1'})
       // now that we have the decrypted user object
       // convert the json string for person property of the user object
        const user=result;

Frequently Asked Questions (FAQ):

1. How does datashield work?

Datashield-AI uses the LokDon 2048bit keyless quantum-resistant encryption algorithm to encrypt your database. Datashield-AI works on row level, which means you can configure it to only encrypt a part of your data or all of your data.

2. How does datashield-AI protect my data?

Datashield-AI first encrypts your data before saving it to the database. It then decrypts the data when you fetch it from the database. This means that your data is always encrypted in the database and only decrypted when you actually need it.

3. How does datashield-AI protect my data from hackers?

Datashield-AI is designed to work with your backend code. This means that your data is encrypted before it is sent to the database. This means that even if a hacker gets direct access to your database, they will not be able to decrypt your data.

4. How does datashield-AI protect my data from my own employees?

Datashield-AI only decrypts data with the same instance you used to encrypt it. This means that even if your employees have access to your database, they will still not be able to decrypt your data.

5. How does datashield-AI prevents data leaks and security breaches?

Datashield-AI becomes your last line of defense against data leaks and security breaches. Datashield-AI ensures that the valuable part of your users' data is stored encrypted in your servers. This means, even if a data leak occurs due to a security breach from the application or network layers, your users' data will still be safe.

Change logs:

Version 1.0.4

  • fixed bug in encrypting objects
  • added FAQ section to readme

Version 1.0.3

  • added support for encrypted arrays
  • added support for encrypted numbers
  • added support for encrypted objects

Version 1.0.2

  • added more schema types
  • added qucik-start-guide for mongoose
  • added test cases to test_mongoose.js

Version 1.0.1

  • added sample data for test
  • added more tests, added custom schema type for mongoose

Version 1.0.0-beta

  • added support for mongoose
  • added support for sql based databases
  • added test cases using mysql package

Package Sidebar


npm i datashield

Weekly Downloads






Unpacked Size

939 kB

Total Files


Last publish


  • lokdonllc