Sealing a JSON object using symmetric key encryption.
iron
provide a neat way to seal a JSON object using symmetric key encryption with message integrity verification!
Get it: npm install iron
Sample usage:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| //Encrypt
const Iron = require("iron");
const obj = {
a: 1,
b: 2,
c: [3, 4, 5],
d: {
e: 'f'
}
};
const password = 'some_not_random_password_that_is_at_least_32_characters';
try {
(async () => {
const sealed = await Iron.seal(obj, password, Iron.defaults);
console.log(sealed);
})();
} catch (err) {
console.log(err.message);
}
|
1
2
3
4
5
6
7
8
| // Decrypt
try {
(async () => {
const unsealed = await Iron.unseal(sealed, password, Iron.defaults);
})();
} catch (err) {
console.log(err.message);
}
|
GIF FTW!