1

I am trying to implement setSecret to encrypt the values in indexeddb but get the error:

"unable to call method setSecret of undefined"

Code Below:

 $(window).load(function () {

   //Database Schema
    var db_schema = {
    stores: [
        {
            name: "Employees",
        }
    ]
}

var secret = "Test";
db.setSecret(secret); 

    db = new ydn.db.Storage('Database', db_schema);

});

Following the link, but not sure where I'm going wrong any ideas:

Anyone encrpyted there indexddb values before?

Thanks

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83

2 Answers2

0

Sorry for documentation behind. I have updated the documentation. Now you have to put encryption key in database options.

var schema = {
    version: 1,
    stores: [{
      name: 'encrypt-store',
      encrypted: true
    }]
};
var options = {
  Encryption: {
    expiration: 1000*15, //  optional data expiration in ms.
    secrets: [{
      name: 'aaaa',
      key: 'aYHF6vfuGHpfWSeRLrPQxZjS5c6HjCscqDqRtZaspJWSMGaW'
    }]
  }
};

var db = new ydn.db.Storage('encrypted-db-name', schema, options);

You have to use "-crypt" module to get that feature. It supports transparent data encryption using sha256 crypto, per record salting and key rotation. You still need server to generate encryption key and send to the client securely. There is also a demo app.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
  • Thanks for the reply I have implemented the above using your example so I know the encryption works. But when I try to store an object that has a number of objects with in it I get the following error in the script: Uncaught RangeError: Maximum call stack size exceeded. – user2956121 Nov 07 '13 at 10:56
  • could you share your code? the library work for any number of objects. – Kyaw Tun Nov 07 '13 at 11:07
0
//Database Creation
    //Database Schema
        var db_schema = {
            stores: [{
                name: "DataTable",
                encrypted: true
            }
            ]
        };

        var options = {
            Encryption: {
                //expiration: 1000 * 15, //  optional data expiration in ms.
                secrets: [{
                    name: 'aaaa',
                    key: 'aYHF6vfuGHpfWS*eRLrPQxZjSó~É5c6HjCscqDqRtZasp¡JWSMGaW'
                }]
            }
        };



        //Create the database with the relevant tables using the schema above
        db = new ydn.db.Storage('Database', db_schema,options);   


$.ajax({
                        type: "POST",
                        url: "/home/DownloadData",
                        data: { File: file },
                        success: function (result) {

                             var Key = result.Data.Key;
                             var DownloadedData= {
                                 Data: result.Data,
                                 Data1: result.Data1,
                                 Data2: result.Data2,
                                Data3: result.Data3
                             };
                             db.put('DataTable', DownloadedData, Key);
                             return false;
                        },
                        error: function (error) {
                            alert("fail");
                        }
                    });
  • The object DownloadedData has a number of objects that have a number of arrays in them. Those arrays then have a number of objects inside them. – user2956121 Nov 07 '13 at 11:31
  • I have only added the following script to my project: am I supposed to use (-crypt" module ) or add it somewhere? – user2956121 Nov 07 '13 at 11:48
  • It works with a number of objects but the Data3 is very large is there any way of splitting the data: result in to objects? It falls over because it is saving the whole object as Data and it exceeds the maximum. – user2956121 Nov 07 '13 at 12:02
  • Just quick note, your setting make data expire after 15 s. – Kyaw Tun Nov 07 '13 at 12:15
  • Just one file. It has crypt module – Kyaw Tun Nov 07 '13 at 12:16
  • Large object should be OK as long as it can be serialized with JSON serailizer. So please do serialization just before inserting, `DownloadedData = JSON.parse(JSON.stringify(DownloadedData));` If JSON serialization fail, you need to split data. – Kyaw Tun Nov 07 '13 at 12:23
  • Unable to stringify the object as its too large, will see how to split the data – user2956121 Nov 07 '13 at 12:51