Published
Edited
Feb 4, 2022
Importers
11 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
encrypt = async ({
secret, password
} = {}) => {
const salt = window.crypto.getRandomValues(new Uint8Array(12));
const key = await deriveKey(password, salt);
const name = "AES-GCM";
const iv = window.crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await window.crypto.subtle.encrypt(
{
name, iv
},
key,
enc.encode(secret)
);
return {
name,
salt: encode64(salt),
iv: encode64(iv),
ciphertext: encode64(ciphertext)
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof decryptedSecret = decrypt({
"name": "AES-GCM",
"salt": "R6IPpW0u06A+sObp",
"iv": "8Qo+fJwwOUBz+UuU",
"ciphertext": "D2Hw1RK41fNnYL3MEbJVSdjkQJK2BfjV4hYwavJqdjsbFl5G8QJQUANHri1hE2eLvADXrkFp8tRt7Yk="
})
Insert cell
Insert cell
Insert cell
Insert cell
async function decode(password, encryptedSecret) {
if (typeof encryptedSecret === 'string') encryptedSecret = JSON.parse(encryptedSecret)
const key = await deriveKey(password, decode64(encryptedSecret.salt));
const secret = await window.crypto.subtle.decrypt(
{
name: encryptedSecret.name,
iv: decode64(encryptedSecret.iv)
},
key,
decode64(encryptedSecret.ciphertext)
);
return new TextDecoder().decode(secret)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more