var ls = new SecureLS();
Contructor accepts a configurable Object with all three keys being optional.
Config keys | Default | Accepts |
---|---|---|
encodingType | Base64 | base64 / aes / des / rabbit/rc4 /'' |
isCompression | true | true / false |
encryptionSecret | PBKDF2 value | String |
var ls = new SecureLS();
// or
var ls = new SecureLS({});
No encoding No data compression i.e. Normal way of storing data
var ls = new SecureLS({
encodingType: '',
isCompression: false
});
Base64 encoding but no data compression
var ls = new SecureLS({
isCompression: false
});
AES encryption and data compression
var ls = new SecureLS({
encodingType: 'aes'
});
RC4 encryption and no data compression
var ls = new SecureLS({
encodingType: 'rc4',
isCompression: false
});
RABBIT encryption, no data compression and custom encryptionSecret
var ls = new SecureLS({
encodingType: 'rc4',
isCompression: false,
encryptionSecret: 's3cr3t$@1'
});
Parameter | Description |
---|---|
key | key to store data in |
data | data to be stored |
ls.set('key-name', {
test: 'secure-ls'
})
Parameter | Description |
---|---|
key | key in which data is stored |
ls.get('key-name'})
Parameter | Description |
---|---|
key | remove key in which data is stored |
ls.remove('key-name')
ls.removeAll()
ls.clear()
ls.getAllKeys()
var ls = new SecureLS();
// set key1
ls.set('key1', {data: 'test'});
ls.get('key1'); // print data
> Output: {data: 'test'}
Example 2: With AES Encryption and Data Compression
var ls = new SecureLS({
encodingType: 'aes'
});
// set key1
ls.set('key1', {data: 'test'});
// print data
ls.get('key1');
> Output: {data: 'test'}
// set another key
ls.set('key2', [1, 2, 3]);
// get all keys
ls.getAllKeys();
> Output: ["key1", "key2"]
// remove all keys
ls.removeAll();
Example 3: With RC4 Encryption but no Data Compression
var ls = new SecureLS({
encodingType: 'rc4',
isCompression: false
});
// set key1
ls.set('key1', {data: 'test'});
// print data
ls.get('key1');
> Output: {data: 'test'}
// set another key
ls.set('key2', [1, 2, 3]);
// get all keys
ls.getAllKeys();
> Output: ["key1", "key2"]
// remove all keys
ls.removeAll();
Example 4: With DES Encryption, no Data Compression and custom secret key
var ls = new SecureLS({
encodingType: 'des',
isCompression: false,
encryptionSecret: 'secret'
});
// set key1
ls.set('key1', {data: 'test'});
ls.get('key1'); // print data
> Output: {data: 'test'}
// set another key
ls.set('key2', [1, 2, 3]);
// get all keys
ls.getAllKeys();
> Output: ["key1", "key2"]
// remove all keys
ls.removeAll();