Skip to content

Commit

Permalink
chore: update examples snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
softvar committed Jun 19, 2024
1 parent 35cf663 commit 1a3e805
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 76 deletions.
1 change: 0 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
yarn check:license
yarn lint
yarn test:prod
yarn build
11 changes: 8 additions & 3 deletions example/aes-compressed-realm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
var data = {data: [{age: 1}, {age: '2'}]};
var aesCRealm1 = new SecureLS({encodingType: 'aes', encryptionSecret: 'secret1', encryptionNamespace: 'realm1'});
var data = { data: [{ age: 1 }, { age: '2' }] };
var aesCRealm1 = new SecureLS({
encodingType: 'aes',
encryptionSecret: 'secret1',
encryptionNamespace: 'realm1',
metaKey: '__meta__',
});
var key1 = 'aes__compressed_1';
var ae = aesCRealm1.AES.encrypt(JSON.stringify(data), '');
var bde = aesCRealm1.AES.decrypt(ae.toString(), '');
var de = bde.toString(aesCRealm1.enc._Utf8);
var aesCRealm2 = new SecureLS({encodingType: 'aes', encryptionSecret: 'secret2', encryptionNamespace: 'realm2'});
var aesCRealm2 = new SecureLS({ encodingType: 'aes', encryptionSecret: 'secret2', encryptionNamespace: 'realm2' });
var key2 = 'aes__compressed_2';
var ae2 = aesCRealm2.AES.encrypt(JSON.stringify(data), '');
var bde2 = aesCRealm2.AES.decrypt(ae2.toString(), '');
Expand Down
12 changes: 6 additions & 6 deletions example/aes-compressed.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var key = 'aes__compressed';
var data = {data: [{age: 1}, {age: '2'}]};
var aes_c = new SecureLS({encodingType: 'aes', encryptionSecret: ''});
ae = aes_c.AES.encrypt(JSON.stringify(data), '')
bde = aes_c.AES.decrypt(ae.toString(), '')
de = bde.toString(aes_c.enc._Utf8)
var data = { data: [{ age: 1 }, { age: '2' }] };
var aes_c = new SecureLS({ encodingType: 'aes', encryptionSecret: '' });
ae = aes_c.AES.encrypt(JSON.stringify(data), '');
bde = aes_c.AES.decrypt(ae.toString(), '');
de = bde.toString(aes_c.enc._Utf8);

aes_c.set(key, data);
console.log('AES Compressed');
console.log(localStorage.getItem(key));
console.log(aes_c.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/aes-uncompressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'aes__uncompressed';
var data = {data: [{age: 1}, {age: '2'}]};
var aes_u = new SecureLS({encodingType: 'aes', isCompression: false});
var data = { data: [{ age: 1 }, { age: '2' }] };
var aes_u = new SecureLS({ encodingType: 'aes', isCompression: false });
ae = aes_u.AES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = aes_u.AES.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(aes_u.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ aes_u.set(key, data);
console.log('AES NOT Compressed');
console.log(localStorage.getItem(key));
console.log(aes_u.get(key));
console.log('____________________________________')
console.log('____________________________________');
4 changes: 2 additions & 2 deletions example/base64-compressed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var key = 'base64__compressed';
var data = {data: [{age: 1}, {age: '2'}]};
var data = { data: [{ age: 1 }, { age: '2' }] };
var b_c = new SecureLS();
ae = b_c.AES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = b_c.AES.decrypt(ae.toString(), 's3cr3t@123');
Expand All @@ -9,4 +9,4 @@ b_c.set(key, data);
console.log('Base64 Compressed');
console.log(localStorage.getItem(key));
console.log(b_c.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/des-compressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'des__compressed';
var data = {data: [{age: 1}, {age: '2'}]};
var des_c = new SecureLS({encodingType: 'des'});
var data = { data: [{ age: 1 }, { age: '2' }] };
var des_c = new SecureLS({ encodingType: 'des' });
ae = des_c.DES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = des_c.DES.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(des_c.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ des_c.set(key, data);
console.log('DES Compressed');
console.log(localStorage.getItem(key));
console.log(des_c.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/des-uncompressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'des__uncompressed';
var data = {data: [{age: 1}, {age: '2'}]};
var des_u = new SecureLS({encodingType: 'des', isCompression: false});
var data = { data: [{ age: 1 }, { age: '2' }] };
var des_u = new SecureLS({ encodingType: 'des', isCompression: false });
ae = des_u.DES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = des_u.DES.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(des_u.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ des_u.set(key, data);
console.log('DES not Compressed');
console.log(localStorage.getItem(key));
console.log(des_u.get(key));
console.log('____________________________________')
console.log('____________________________________');
72 changes: 38 additions & 34 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<title>Example Page</title>
<script type="text/javascript" src="../dist/secure-ls.js"></script>
<script type="text/javascript" src="vendor/screenlog.min.js"></script>
<head>
<title>Example Page</title>
<script type="text/javascript" src="../dist/secure-ls.js"></script>
<script type="text/javascript">
window.SecureLS = SecureLS.default;
</script>
<script type="text/javascript" src="vendor/screenlog.min.js"></script>
</head>
<body>
Open console to check localStorage data.
<br />
All of the console output from various examples will be log here. Scroll within it to view all logs.
<br /><br />
Input:
<pre>{"data":[{"age":1},{"age":"2"}]}</pre>
Output:
<pre>{"data":[{"age":1},{"age":"2"}]}</pre>
<script type="text/javascript">
screenLog.init({
autoScroll: false,
});
</script>

</head>
<body>
Open console to check localStorage data.
<br />
All of the console output from various examples will be log here. Scroll within it to view all logs.
<br /><br />
Input: <pre>{"data":[{"age":1},{"age":"2"}]}</pre>
Output: <pre>{"data":[{"age":1},{"age":"2"}]}</pre>
<script type="text/javascript">
screenLog.init({
autoScroll: false
});
</script>

<script type="text/javascript" src="standard.js"></script>
<script type="text/javascript" src="only-base64.js"></script>
<script type="text/javascript" src="only-compressed.js"></script>
<script type="text/javascript" src="base64-compressed.js"></script>
<script type="text/javascript" src="aes-compressed.js"></script>
<script type="text/javascript" src="aes-compressed-realm.js"></script>
<script type="text/javascript" src="aes-uncompressed.js"></script>
<script type="text/javascript" src="des-compressed.js"></script>
<script type="text/javascript" src="des-uncompressed.js"></script>
<script type="text/javascript" src="rabbit-compressed.js"></script>
<script type="text/javascript" src="rabbit-uncompressed.js"></script>
<script type="text/javascript" src="rc4-compressed.js"></script>
<script type="text/javascript" src="rc4-uncompressed.js"></script>
</body>
</html>
<script type="text/javascript" src="standard.js"></script>
<script type="text/javascript" src="only-base64.js"></script>
<script type="text/javascript" src="only-compressed.js"></script>
<script type="text/javascript" src="base64-compressed.js"></script>
<script type="text/javascript" src="aes-compressed.js"></script>
<script type="text/javascript" src="aes-compressed-realm.js"></script>
<script type="text/javascript" src="aes-uncompressed.js"></script>
<script type="text/javascript" src="des-compressed.js"></script>
<script type="text/javascript" src="des-uncompressed.js"></script>
<script type="text/javascript" src="rabbit-compressed.js"></script>
<script type="text/javascript" src="rabbit-uncompressed.js"></script>
<script type="text/javascript" src="rc4-compressed.js"></script>
<script type="text/javascript" src="rc4-uncompressed.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions example/only-base64.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'only__base64';
var data = {data: [{age: 1}, {age: '2'}]};
var o_b = new SecureLS({isCompression: false});
var data = { data: [{ age: 1 }, { age: '2' }] };
var o_b = new SecureLS({ isCompression: false });
ae = o_b.AES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = o_b.AES.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(o_b.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ o_b.set(key, data);
console.log('Only Base64, no compression');
console.log(localStorage.getItem(key));
console.log(o_b.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/only-compressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'only__compressed';
var data = {data: [{age: 1}, {age: '2'}]};
var o_c = new SecureLS({encodingType: ''});
var data = { data: [{ age: 1 }, { age: '2' }] };
var o_c = new SecureLS({ encodingType: '' });
ae = o_c.AES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = o_c.AES.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(o_c.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ o_c.set(key, data);
console.log('Only Compression, no encoding/encryption');
console.log(localStorage.getItem(key));
console.log(o_c.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/rabbit-compressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'rabbit__compressed';
var data = {data: [{age: 1}, {age: '2'}]};
var rabbit_c = new SecureLS({encodingType: 'rabbit'});
var data = { data: [{ age: 1 }, { age: '2' }] };
var rabbit_c = new SecureLS({ encodingType: 'rabbit' });
ae = rabbit_c.RABBIT.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = rabbit_c.RABBIT.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(rabbit_c.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ rabbit_c.set(key, data);
console.log('RABBIT Compressed');
console.log(localStorage.getItem(key));
console.log(rabbit_c.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/rabbit-uncompressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'rabbit__uncompressed';
var data = {data: [{age: 1}, {age: '2'}]};
var rabbit_u = new SecureLS({encodingType: 'rabbit', isCompression: false});
var data = { data: [{ age: 1 }, { age: '2' }] };
var rabbit_u = new SecureLS({ encodingType: 'rabbit', isCompression: false });
ae = rabbit_u.RABBIT.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = rabbit_u.RABBIT.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(rabbit_u.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ rabbit_u.set(key, data);
console.log('RABBIT not Compressed');
console.log(localStorage.getItem(key));
console.log(rabbit_u.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/rc4-compressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'rc4__compressed';
var data = {data: [{age: 1}, {age: '2'}]};
var rc4_c = new SecureLS({encodingType: 'rc4'});
var data = { data: [{ age: 1 }, { age: '2' }] };
var rc4_c = new SecureLS({ encodingType: 'rc4' });
ae = rc4_c.RC4.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = rc4_c.RC4.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(rc4_c.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ rc4_c.set(key, data);
console.log('RC4 Compressed');
console.log(localStorage.getItem(key));
console.log(rc4_c.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/rc4-uncompressed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'rc4__uncompressed';
var data = {data: [{age: 1}, {age: '2'}]};
var rc4_u = new SecureLS({encodingType: 'rc4', isCompression: false});
var data = { data: [{ age: 1 }, { age: '2' }] };
var rc4_u = new SecureLS({ encodingType: 'rc4', isCompression: false });
ae = rc4_u.RC4.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = rc4_u.RC4.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(rc4_u.enc._Utf8);
Expand All @@ -9,4 +9,4 @@ rc4_u.set(key, data);
console.log('RC4 not Compressed');
console.log(localStorage.getItem(key));
console.log(rc4_u.get(key));
console.log('____________________________________')
console.log('____________________________________');
6 changes: 3 additions & 3 deletions example/standard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var key = 'standard';
var data = {data: [{age: 1}, {age: '2'}]};
var a = new SecureLS({encodingType: '', isCompression: false});
var data = { data: [{ age: 1 }, { age: '2' }] };
var a = new SecureLS({ encodingType: '', isCompression: false });
ae = a.AES.encrypt(JSON.stringify(data), 's3cr3t@123');
bde = a.AES.decrypt(ae.toString(), 's3cr3t@123');
de = bde.toString(a.enc._Utf8);
Expand All @@ -10,4 +10,4 @@ console.log('____________________________________');
console.log('Standard Case: no compression, no encryption / encoding');
console.log(localStorage.getItem(key));
console.log(a.get(key));
console.log('____________________________________');
console.log('____________________________________');

0 comments on commit 1a3e805

Please sign in to comment.