-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample.js
29 lines (23 loc) · 795 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const util = require('util')
const cryptoJSON = require('../')
const algorithm = 'aes-256-cbc'
const encoding = 'hex'
const input = {
hello: {
bar: ['hello', 'world'],
baz: {
secret: 'hide a secret',
b: { test: 1 }
}
}
}
const password = 'random password 32 bytes length.'
// keys act like a white list, so for example if you want to encrypt a nested
// key "secret" you also need to specify its parent keys,
// i.e. "secret", "baz", "hello" in the above input object
const keys = ['hello', 'baz', 'secret']
const output = cryptoJSON.encrypt(
input, password, { encoding, keys, algorithm }
)
console.log(util.inspect(input, { showHidden: false, depth: null, colors: true }))
console.log(util.inspect(output, { showHidden: false, depth: null, colors: true }))