UNPKG

crypt.io

Version:

Encryption enabled browser storage

129 lines (114 loc) 4.68 kB
<html> <head> <script type="text/javascript" src="../3rd-party/sjcl/sjcl.js"></script> <script type="text/javascript" src="../dist/crypt.io.min.js"></script> <script> var storage = cryptio, inventory = [{ "SKU": "39-48949", "Price": 618, "Item": "Snowboard" }, { "SKU": "99-28128", "Price": 78.99, "Item": "Cleats" }, { "SKU": "83-38285", "Price": 3.99, "Item": "Hockey Puck" }]; document.write('<b>Testing default use case</b><br/>'); storage.set('inventory', inventory, function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(results+'<br/>'); document.write(window.localStorage.getItem('inventory')+'<br/>'); }); storage.get('inventory', function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(JSON.stringify(results)+'<br/>'); }); document.write('<br/><b>Testing use of sessionStorage option</b><br/>'); var options = { storage: "session" } storage.set(options, 'inventory', inventory, function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(results+'<br/>'); document.write(window.localStorage.getItem('inventory')+'<br/>'); }); storage.get(options, 'inventory', function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(JSON.stringify(results)+'<br/>'); }); document.write('<br/><b>Testing use of depreciated (fallback) to cookies</b><br/>'); var options = { storage: "cookies" } storage.set(options, 'inventory', inventory, function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(results+'<br/>'); document.write(window.localStorage.getItem('inventory')+'<br/>'); }); storage.get(options, 'inventory', function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(JSON.stringify(results)+'<br/>'); }); document.write('<br/><b>Testing user provided passphrase</b><br/>'); var options = { passphrase: "secret squirrel sauce" } storage.set(options, 'inventory', inventory, function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(results+'<br/>'); document.write(window.localStorage.getItem('inventory')+'<br/>'); }); storage.get(options, 'inventory', function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(JSON.stringify(results)+'<br/>'); }); document.write('<br/><b>Testing user provided passphrase (paranoid example)</b><br/>'); var options = { passphrase: sjcl.codec.base64.fromBits(sjcl.hash.sha256.hash(sjcl.misc.pbkdf2("secret squirrel sauce", sjcl.random.randomWords(2), 10000, 512))) } storage.set(options, 'inventory', inventory, function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(results+'<br/>'); document.write(window.localStorage.getItem('inventory')+'<br/>'); }); storage.get(options, 'inventory', function(err, results){ if (err) { document.write(err+'<br/>'); return; } document.write(JSON.stringify(results)+'<br/>'); }); </script> </head> </html>