Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including whstorage with all npm packages installed. Try it out:

var whstorage = require("whstorage")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

whstorage v1.2.1

whSotorage is a way to encrypt localSotage

WHStorage Client-Side

whSotorage is a way to encrypt localSotage

Installation

npm install express-whs whstorage --save

Usage

client/app.js


/*
* Get KEY and PREFIX
*/
fetch('/api')
.then((response) => response.json())
.then((data) => {
    /*
    * Configure WHS, send parames
    */
    whStorage.init({
        key: data.whKey,
        prefix: data.prefix
    });
    /*
    * Store Data to localStorage throw whs
    */
    whStorage.set('user', {name: "david",password: "lolita123"})
    whStorage.set('setting', {video: true,audio: false})
})

/*
* wait one second, because we send unsynchronized requests using fetch
* and get data form storage.
*/
setTimeout(() => {
    let user = whStorage.get('user')
    let setting = whStorage.get('setting')
    console.log(user)
    console.log(setting)
}, 1000)


/*
* try to decrypt without key
*/
// let value = sjcl.decrypt("bla123", localStorage.getItem('wh_user'))
// console.log(value)

server/app.js


const express = require('express')
const whs = require('express-whs')

/*
* Define Exprees App
*/
const app = express();

app.use(whs({
    prefix: 'wh',
    secret: 'thisismysecret',
    keySize: 36
}))

/*
* send to client
*/
app.get('/api', (req, res, next) => {
    res.send({
        whKey: req.wh_Key,
        prefix: req.wh_prefix
    })
})

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free