Question

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

Was it helpful?

Solution 2

//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");
                        }
                    });

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top