-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathencrypt_structured.mjs
37 lines (30 loc) · 1.03 KB
/
encrypt_structured.mjs
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
30
31
32
33
34
35
36
37
/* eslint-disable no-console */
import process from "node:process";
import { PangeaConfig, VaultService, Vault } from "pangea-node-sdk";
const token = process.env.PANGEA_VAULT_TOKEN;
const config = new PangeaConfig({ domain: process.env.PANGEA_DOMAIN });
const vault = new VaultService(token, config);
(async () => {
// First create an encryption key, either from the Pangea Console or
// programmatically as below.
const createResponse = await vault.symmetricGenerate({
algorithm: Vault.SymmetricAlgorithm.AES256_CFB,
purpose: Vault.KeyPurpose.ENCRYPTION,
name: "Node.js encrypt example " + Date.now(),
});
const encryptionKeyId = createResponse.result.id;
// Structured data that we'll encrypt.
const data = {
foo: [1, 2, "bar", "baz"],
some: "thing",
};
const response = await vault.encryptStructured({
id: encryptionKeyId,
structured_data: data,
filter: "$.foo[2:4]",
});
console.log(
"Encrypted result: %s",
JSON.stringify(response.result.structured_data, null, 2)
);
})();