特性:secure-ls源代码下载
npm install secure-ls
- 使用
AES
。DES
。Rabbit
和RC4
等各种加密方式保护数据。 ( 默认为Base64
编码)。 - 将数据存储到
localStorage
之前压缩数据以保存额外的字节( 默认为true
)。 - 通过
localStorage
API实现高级API包装,提供其他基本工具。 - 将数据保存在多个键 inside
localStorage
和secure-ls
将始终记住它的创建。
用法
示例 1: 使用 default
设置 换句话说,Base64
编码和数据压缩
var ls = new SecureLS();
ls.set('key1', {data: 'test'});//set key1
ls.get('key1');//print data
{data: 'test'}
示例 2: 使用 AES
加密和数据压缩
var ls = new SecureLS({encodingType: 'aes'});
ls.set('key1', {data: 'test'});//set key1
ls.get('key1');//print data
{data: 'test'}
ls.set('key2', [1, 2, 3]);//set another key
ls.getAllKeys();//get all keys
["key1","key2"]
ls.removeAll();//remove all keys
示例 3: 使用 RC4
加密但没有数据压缩
var ls = new SecureLS({encodingType: 'rc4', isCompression: false});
ls.set('key1', {data: 'test'});//set key1
ls.get('key1');//print data
{data: 'test'}
ls.set('key2', [1, 2, 3]);//set another key
ls.getAllKeys();//get all keys
["key1","key2"]
ls.removeAll();//remove all keys
示例 4: 使用 DES
加密,没有数据压缩和自定义密钥
var ls = new SecureLS({encodingType: 'des', isCompression: false, encryptionSecret: 'my-secret-key'});
ls.set('key1', {data: 'test'});//set key1
ls.get('key1');//print data
{data: 'test'}
ls.set('key2', [1, 2, 3]);//set another key
ls.getAllKeys();//get all keys
["key1","key2"]
ls.removeAll();//remove all keys
API文档
在使用之前创建实例/引用。
var ls = new SecureLS();
Contructor
接受一个可以配置的Object
,其中所有三个键都是可选的.
配置密钥默认接受 | ||
encodingType | Base64 | Base64 /AES /DES /Rabbit /RC4 /'' |
isCompression | true | true /false |
encryptionSecret | PBKDF2值 | 字符串 |
注意:如果只使用 AES
,DES
,RC4
,Rabbit
就会对数据进行加密和解密,如果没有选择编码/base64编码方法,库将丢弃它。
示例:
- 无配置或者空对象 换句话说,默认的
Base64 Encoding
Data compression
var ls = new SecureLS();
//or
var ls = new SecureLS({});
- 无编码无数据压缩 换句话说,
Normal
存储数据的方法
var ls = new SecureLS({encodingType: '', isCompression: false});
Base64
编码,但有字节的no
数据压缩
var ls = new SecureLS({isCompression: false});
AES
加密和英镑Data compression
var ls = new SecureLS({encodingType: 'aes'});
RC4
加密和收费的no
数据压缩
var ls = new SecureLS({encodingType: 'rc4', isCompression: false});
Rabbit
加密,no
数据压缩和custom
encryptionSecret
var ls = new SecureLS({encodingType: 'rc4', isCompression: false, encryptionSecret: 's3cr3tPa$$w0rd@123'});